Issue #398: tests for extension conflict resolution added.
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t01.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t01.dart
similarity index 100%
rename from LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t01.dart
rename to LanguageFeatures/Extension-methods/extension_conflict_resolution_t01.dart
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t02.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t02.dart
similarity index 100%
rename from LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t02.dart
rename to LanguageFeatures/Extension-methods/extension_conflict_resolution_t02.dart
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t03.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t03.dart
similarity index 100%
rename from LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t03.dart
rename to LanguageFeatures/Extension-methods/extension_conflict_resolution_t03.dart
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t04.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t04.dart
similarity index 100%
rename from LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t04.dart
rename to LanguageFeatures/Extension-methods/extension_conflict_resolution_t04.dart
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t05.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t05.dart
similarity index 100%
rename from LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t05.dart
rename to LanguageFeatures/Extension-methods/extension_conflict_resolution_t05.dart
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t06.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t06.dart
similarity index 100%
rename from LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t06.dart
rename to LanguageFeatures/Extension-methods/extension_conflict_resolution_t06.dart
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t07.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t07.dart
similarity index 98%
rename from LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t07.dart
rename to LanguageFeatures/Extension-methods/extension_conflict_resolution_t07.dart
index 5511513..69aa792 100644
--- a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t07.dart
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t07.dart
@@ -25,7 +25,6 @@
* @description Check that An extension with [on] type clause [T1] is more
* specific than another extension with [on] type clause [T2] if instantiated
* type of [T1] is a subtype if instantiated type of [T2]
- * @compile-error
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=extension-methods
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t07.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t08.dart
similarity index 70%
copy from LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t07.dart
copy to LanguageFeatures/Extension-methods/extension_conflict_resolution_t08.dart
index 5511513..8d4ddee 100644
--- a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t07.dart
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t08.dart
@@ -22,34 +22,26 @@
* 4. not vice versa, or
* 5. the instantiate-to-bounds type of [T1] is a subtype of the
* instantiate-to-bounds type of [T2] and not vice versa.
- * @description Check that An extension with [on] type clause [T1] is more
- * specific than another extension with [on] type clause [T2] if instantiated
- * type of [T1] is a subtype if instantiated type of [T2]
- * @compile-error
+ * @description Check that [SmartIterable<T> on Iterable<T>] is less specific
+ * than [SmartIterable<T> on List<T>]
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=extension-methods
import "../../Utils/expect.dart";
-class A {}
-class B extends A {}
-class C extends B {}
-
-extension A_extension on A {
- int get getType => 1;
+extension SmartIterable<T> on Iterable<T> {
+ int checkme() {
+ return(length);
+ }
}
-extension B_extension on B {
- int get getType => 2;
-}
-
-extension C_extension on C {
- int get getType => 3;
+extension SmartList<T> on List<T> {
+ int checkme() {
+ return(0);
+ }
}
main() {
- Expect.equals(1, A().getType);
- Expect.equals(1, B().getType);
- Expect.equals(1, C().getType);
+ List<int> x = [1, 2, 3];
+ Expect.equals(0, x.checkme());
}
-
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t09.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t09.dart
new file mode 100644
index 0000000..d1a109a
--- /dev/null
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t09.dart
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
+ * for details. All rights reserved. Use of this source code is governed by a
+ * BSD-style license that can be found in the LICENSE file.
+ */
+/**
+ * @assertion If more than one extension applies to a specific member
+ * invocation, then we resort to a heuristic to choose one of the extensions to
+ * apply. If exactly one of them is "more specific" than all the others, that
+ * one is chosen. Otherwise it is a compile-time error.
+ *
+ * An extension with [on] type clause [T1] is more specific than another
+ * extension with [on] type clause [T2] iff
+ *
+ * 1. The latter extension is declared in a platform library, and the former
+ * extension is not
+ * 2. they are both declared in platform libraries or both declared in
+ * non-platform libraries, and
+ * 3. the instantiated type (the type after applying type inference from the
+ * receiver) of [T1] is a subtype of the instantiated type of [T2] and
+ * either
+ * 4. not vice versa, or
+ * 5. the instantiate-to-bounds type of [T1] is a subtype of the
+ * instantiate-to-bounds type of [T2] and not vice versa.
+ * @description Check that:
+ * For [x.best()], the most specific one is [BestList]. Because [List<int>] is a
+ * proper subtype of both [iterable<int>] and [<List<num>], we expect BestList
+ * to be the best implementation. The return type causes [v] to have type [int].
+ * If we had chosen [BestSpec] instead, the return type could only be [num],
+ * which is one of the reasons why we choose the most specific instantiated type
+ * as the winner.
+ * For [y.best()], the most specific extension is [BestSpec]. The instantiated
+ * on types that are compared are [Iterable<num>] for [BestCom] and [List<num>]
+ * for the two other. Using the instantiate-to-bounds types as tie-breaker, we
+ * find that [List<Object>] is less precise than [List<num>], so the code of
+ * [BestSpec] has more precise information available for its method
+ * implementation. The type of [w] becomes [num].
+ * @author iarkh@unipro.ru
+ */
+// SharedOptions=--enable-experiment=extension-methods
+import "../../Utils/expect.dart";
+
+extension BestCom<T extends num> on Iterable<T> {
+ T best() { throw null; }
+}
+extension BestList<T> on List<T> {
+ T best() { return(null); }
+}
+
+extension BestSpec on List<num> {
+ num best() { return(0); }
+}
+
+main() {
+ List<int> x = [1, 2, 3];
+ Expect.isNull(x.best());
+ List<num> y = [1, 2, 3];
+ Expect.equals(0, y.best());
+}
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t07.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t10.dart
similarity index 78%
copy from LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t07.dart
copy to LanguageFeatures/Extension-methods/extension_conflict_resolution_t10.dart
index 5511513..4c20b7d 100644
--- a/LanguageFeatures/Extension-methods/extension_conflict_resolution_A01_t07.dart
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t10.dart
@@ -24,32 +24,25 @@
* instantiate-to-bounds type of [T2] and not vice versa.
* @description Check that An extension with [on] type clause [T1] is more
* specific than another extension with [on] type clause [T2] if instantiated
- * type of [T1] is a subtype if instantiated type of [T2]
- * @compile-error
+ * type of [T1] is a subtype if instantiated type of [T2] and i-2-b type of [T1]
+ * is a subtype of the instantiate type of [T2]
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=extension-methods
import "../../Utils/expect.dart";
-class A {}
-class B extends A {}
-class C extends B {}
+class A<X extends A<X>> {}
-extension A_extension on A {
- int get getType => 1;
+extension ext1<X extends A<X>> on A<X> {
+ bool checkme => false;
}
-extension B_extension on B {
- int get getType => 2;
-}
-
-extension C_extension on C {
- int get getType => 3;
+extension ext2<X extends A<Null>> on A<X> {
+ int get getType => true;
}
main() {
- Expect.equals(1, A().getType);
- Expect.equals(1, B().getType);
- Expect.equals(1, C().getType);
+ A a = new A<Null>();
+ Expect.isTrue(a.checkme());
}