Fixed Issue #420: positive test case for the conflicting resolutions added, there should not be errors if members are not called directly.
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t06.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t06.dart
index 0c818f9..baa962b 100644
--- a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t06.dart
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t06.dart
@@ -23,7 +23,8 @@
* 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 compile time error is thrown if two extension members
- * with [on] type clause are equitable
+ * with [on] type clause are equitable and a member from the conflicting
+ * extensions is referenced.
* @compile-error
* @author iarkh@unipro.ru
*/
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t07.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t07.dart
index d67fcc5..b850c97 100644
--- a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t07.dart
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t07.dart
@@ -22,33 +22,24 @@
* 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]
+ * @description Check that compile time error is not thrown if two extension
+ * members with [on] type clause are equitable, but not referenced.
* @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 MyFancyExt1 on Object {
+ bool get isExt1 => true;
}
-extension B_extension on B {
- int get getType => 2;
-}
-
-extension C_extension on C {
- int get getType => 3;
+extension MyIntFancyExt2 on Object {
+ bool get isExt1 => false;
}
main() {
- Expect.equals(1, A().getType);
- Expect.equals(2, B().getType);
- Expect.equals(3, C().getType);
+ Expect.isTrue(MyFancyExt1("").isExt1);
+ Expect.isFalse(MyFancyExt2("").isExt1);
}
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t08.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t08.dart
index 8d4ddee..d67fcc5 100644
--- a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t08.dart
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t08.dart
@@ -22,26 +22,33 @@
* 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 [SmartIterable<T> on Iterable<T>] is less specific
- * than [SmartIterable<T> on List<T>]
+ * @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]
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=extension-methods
import "../../Utils/expect.dart";
-extension SmartIterable<T> on Iterable<T> {
- int checkme() {
- return(length);
- }
+class A {}
+class B extends A {}
+class C extends B {}
+
+extension A_extension on A {
+ int get getType => 1;
}
-extension SmartList<T> on List<T> {
- int checkme() {
- return(0);
- }
+extension B_extension on B {
+ int get getType => 2;
+}
+
+extension C_extension on C {
+ int get getType => 3;
}
main() {
- List<int> x = [1, 2, 3];
- Expect.equals(0, x.checkme());
+ Expect.equals(1, A().getType);
+ Expect.equals(2, B().getType);
+ Expect.equals(3, C().getType);
}
+
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t09.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t09.dart
index d1a109a..8d4ddee 100644
--- a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t09.dart
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t09.dart
@@ -22,38 +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:
- * 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].
+ * @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";
-extension BestCom<T extends num> on Iterable<T> {
- T best() { throw null; }
-}
-extension BestList<T> on List<T> {
- T best() { return(null); }
+extension SmartIterable<T> on Iterable<T> {
+ int checkme() {
+ return(length);
+ }
}
-extension BestSpec on List<num> {
- num best() { return(0); }
+extension SmartList<T> on List<T> {
+ int checkme() {
+ return(0);
+ }
}
main() {
List<int> x = [1, 2, 3];
- Expect.isNull(x.best());
- List<num> y = [1, 2, 3];
- Expect.equals(0, y.best());
+ Expect.equals(0, x.checkme());
}
diff --git a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t10.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t10.dart
index 6d155d5..d1a109a 100644
--- a/LanguageFeatures/Extension-methods/extension_conflict_resolution_t10.dart
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t10.dart
@@ -22,27 +22,38 @@
* 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] and i-2-b type of [T1]
- * is a subtype of the instantiate type of [T2]
+ * @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";
-class A<X extends A<X>> {}
-
-extension ext1<X extends A<X>> on A<X> {
- bool get checkme => false;
+extension BestCom<T extends num> on Iterable<T> {
+ T best() { throw null; }
+}
+extension BestList<T> on List<T> {
+ T best() { return(null); }
}
-extension ext2<X extends A<Null>> on A<X> {
- bool get checkme => true;
+extension BestSpec on List<num> {
+ num best() { return(0); }
}
main() {
- A a = new A<Null>();
- Expect.isTrue(a.checkme);
+ 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_t11.dart b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t11.dart
new file mode 100644
index 0000000..6d155d5
--- /dev/null
+++ b/LanguageFeatures/Extension-methods/extension_conflict_resolution_t11.dart
@@ -0,0 +1,48 @@
+/*
+ * 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 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] 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<X extends A<X>> {}
+
+extension ext1<X extends A<X>> on A<X> {
+ bool get checkme => false;
+}
+
+extension ext2<X extends A<Null>> on A<X> {
+ bool get checkme => true;
+}
+
+main() {
+ A a = new A<Null>();
+ Expect.isTrue(a.checkme);
+}
+