Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Unified Diff: pkg/analyzer/test/generated/type_system_test.dart

Issue 2291103004: fix #25740 again, making sure we have the substituted bound in inference (Closed)
Patch Set: merge and add todo Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/generated/type_system_test.dart
diff --git a/pkg/analyzer/test/generated/type_system_test.dart b/pkg/analyzer/test/generated/type_system_test.dart
index d7d72f87fe05264b02d0510950c1a1729b6bb0d6..2b3248de880652a391a6fba9dce16c12b0daedf1 100644
--- a/pkg/analyzer/test/generated/type_system_test.dart
+++ b/pkg/analyzer/test/generated/type_system_test.dart
@@ -881,6 +881,80 @@ class StrongGenericFunctionInferenceTest {
]);
}
+ void test_boundedByOuterClass() {
+ // Regression test for https://github.com/dart-lang/sdk/issues/25740.
+
+ // class A {}
+ var a = ElementFactory.classElement('A', objectType);
+
+ // class B extends A {}
+ var b = ElementFactory.classElement('B', a.type);
+
+ // class C<T extends A> {
+ var c = ElementFactory.classElement('C', objectType, ['T']);
+ (c.typeParameters[0] as TypeParameterElementImpl).bound = a.type;
+ // S m<S extends T>(S);
+ var s = TypeBuilder.variable('S');
+ (s.element as TypeParameterElementImpl).bound = c.typeParameters[0].type;
+ var m = ElementFactory.methodElement('m', s, [s]);
+ m.typeParameters = [s.element];
+ c.methods = [m];
+ // }
+
+ // C<Object> cOfObject;
+ var cOfObject = c.type.instantiate([objectType]);
+ // C<A> cOfA;
+ var cOfA = c.type.instantiate([a.type]);
+ // C<B> cOfB;
+ var cOfB = c.type.instantiate([b.type]);
+ // B b;
+ // cOfB.m(b); // infer <B>
+ expect(_inferCall(cOfB.getMethod('m').type, [b.type]), [b.type, b.type]);
+ // cOfA.m(b); // infer <B>
+ expect(_inferCall(cOfA.getMethod('m').type, [b.type]), [a.type, b.type]);
+ // cOfObject.m(b); // infer <B>
+ expect(_inferCall(cOfObject.getMethod('m').type, [b.type]),
+ [objectType, b.type]);
+ }
+
+ void test_boundedByOuterClassSubstituted() {
+ // Regression test for https://github.com/dart-lang/sdk/issues/25740.
+
+ // class A {}
+ var a = ElementFactory.classElement('A', objectType);
+
+ // class B extends A {}
+ var b = ElementFactory.classElement('B', a.type);
+
+ // class C<T extends A> {
+ var c = ElementFactory.classElement('C', objectType, ['T']);
+ (c.typeParameters[0] as TypeParameterElementImpl).bound = a.type;
+ // S m<S extends Iterable<T>>(S);
+ var s = TypeBuilder.variable('S');
+ var iterableOfT = iterableType.instantiate([c.typeParameters[0].type]);
+ (s.element as TypeParameterElementImpl).bound = iterableOfT;
+ var m = ElementFactory.methodElement('m', s, [s]);
+ m.typeParameters = [s.element];
+ c.methods = [m];
+ // }
+
+ // C<Object> cOfObject;
+ var cOfObject = c.type.instantiate([objectType]);
+ // C<A> cOfA;
+ var cOfA = c.type.instantiate([a.type]);
+ // C<B> cOfB;
+ var cOfB = c.type.instantiate([b.type]);
+ // List<B> b;
+ var listOfB = listType.instantiate([b.type]);
+ // cOfB.m(b); // infer <B>
+ expect(_inferCall(cOfB.getMethod('m').type, [listOfB]), [b.type, listOfB]);
+ // cOfA.m(b); // infer <B>
+ expect(_inferCall(cOfA.getMethod('m').type, [listOfB]), [a.type, listOfB]);
+ // cOfObject.m(b); // infer <B>
+ expect(_inferCall(cOfObject.getMethod('m').type, [listOfB]),
+ [objectType, listOfB]);
+ }
+
void test_boundedRecursively() {
// class Clonable<T extends Clonable<T>>
ClassElementImpl clonable =
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/member.dart ('k') | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698