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

Unified Diff: pkg/analyzer/test/src/task/strong/inferred_type_test.dart

Issue 2762863002: Issue 28580. Relax instantiate to bounds. (Closed)
Patch Set: Created 3 years, 9 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/src/task/strong/inferred_type_test.dart
diff --git a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
index 67f38510f4682cc1d1fb315d008cd45f5e71556c..021fd70e60a145143130c0c0d8251b6396fd0a67 100644
--- a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
+++ b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
@@ -11,6 +11,7 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
+import '../../summary/element_text.dart';
import 'strong_test_helper.dart';
void main() {
@@ -4027,72 +4028,168 @@ var x = /*info:USE_OF_VOID_RESULT*/f();
expect(x.type.toString(), 'void');
}
- test_instantiateToBounds_generic2_hasBound_definedAfter() async {
+ test_instantiateToBounds_invokeConstructor_noBound() async {
+ var unit = await checkFileElement('''
+class C<T> {}
+var x = /*info:INFERRED_TYPE_ALLOCATION*/new C();
+''');
+ expect(unit.topLevelVariables[0].type.toString(), 'C<dynamic>');
+ }
+
+ test_instantiateToBounds_invokeConstructor_typeArgsExact() async {
+ var unit = await checkFileElement('''
+class C<T extends num> {}
+var x = new C<int>();
+''');
+ expect(unit.topLevelVariables[0].type.toString(), 'C<int>');
+ }
+
+ test_instantiateToBounds_notGeneric() async {
var unit = await checkFileElement(r'''
+class A {}
+class B<T extends A> {}
+B v = null;
+''');
+ checkElementText(
+ unit.library,
+ r'''
+class A {
+}
+class B<T extends A> {
+}
+B<A> v;
+''');
+ }
+
+ test_instantiateToBounds_typeName_error1() async {
+ var unit = await checkFileElement(r'''
+class A<T1 extends int, T2 extends T1> {}
class B<T extends /*error:NOT_INSTANTIATED_BOUND*/A> {}
-class A<T extends int> {}
B v = null;
''');
- expect(unit.topLevelVariables[0].type.toString(), 'B<A<dynamic>>');
+ checkElementText(
+ unit.library,
+ r'''
+class A<T1 extends int, T2 extends T1> {
+}
+class B<T extends A<int, int>> {
+}
+B<A<int, int>> v;
+''');
}
- test_instantiateToBounds_generic2_hasBound_definedBefore() async {
+ test_instantiateToBounds_typeName_error2() async {
var unit = await checkFileElement(r'''
-class A<T extends int> {}
+class A<T1 extends T2, T2 extends int> {}
class B<T extends /*error:NOT_INSTANTIATED_BOUND*/A> {}
B v = null;
''');
- expect(unit.topLevelVariables[0].type.toString(), 'B<A<dynamic>>');
+ checkElementText(
+ unit.library,
+ r'''
+class A<T1 extends T2, T2 extends int> {
+}
+class B<T extends A<int, int>> {
+}
+B<A<int, int>> v;
+''');
}
- test_instantiateToBounds_generic2_noBound() async {
+ test_instantiateToBounds_typeName_error3() async {
var unit = await checkFileElement(r'''
-class A<T> {}
-class B<T extends A> {}
+class A<T1 extends int, T2 extends List<T1>> {}
+class B<T extends /*error:NOT_INSTANTIATED_BOUND*/A> {}
B v = null;
''');
- expect(unit.topLevelVariables[0].type.toString(), 'B<A<dynamic>>');
+ checkElementText(
+ unit.library,
+ r'''
+class A<T1 extends int, T2 extends List<T1>> {
+}
+class B<T extends A<int, List<int>>> {
+}
+B<A<int, List<int>>> v;
+''');
}
- test_instantiateToBounds_generic_hasBound_definedAfter() async {
+ @failingTest
+ test_instantiateToBounds_typeName_OK_hasBound_definedAfter() async {
var unit = await checkFileElement(r'''
-A v = null;
+class B<T extends A> {}
class A<T extends int> {}
+B v = null;
+''');
+ checkElementText(
+ unit.library,
+ r'''
+class B<T extends A<int>> {
+}
+class A<T extends int> {
+}
+B<A<int>> v;
''');
- expect(unit.topLevelVariables[0].type.toString(), 'A<int>');
}
- test_instantiateToBounds_generic_hasBound_definedBefore() async {
+ test_instantiateToBounds_typeName_OK_hasBound_definedBefore() async {
var unit = await checkFileElement(r'''
class A<T extends int> {}
-A v = null;
+class B<T extends A> {}
+B v = null;
+''');
+ checkElementText(
+ unit.library,
+ r'''
+class A<T extends int> {
+}
+class B<T extends A<int>> {
+}
+B<A<int>> v;
''');
- expect(unit.topLevelVariables[0].type.toString(), 'A<int>');
}
- test_instantiateToBounds_invokeConstructor_noBound() async {
- var unit = await checkFileElement('''
-class C<T> {}
-var x = /*info:INFERRED_TYPE_ALLOCATION*/new C();
+ test_instantiateToBounds_typeName_OK_inBound_hasBound_definedAfter() async {
+ var unit = await checkFileElement(r'''
+A v = null;
+class A<T extends int> {}
+''');
+ checkElementText(
+ unit.library,
+ r'''
+class A<T extends int> {
+}
+A<int> v;
''');
- expect(unit.topLevelVariables[0].type.toString(), 'C<dynamic>');
}
- test_instantiateToBounds_invokeConstructor_typeArgsExact() async {
- var unit = await checkFileElement('''
-class C<T extends num> {}
-var x = new C<int>();
+ test_instantiateToBounds_typeName_OK_inBound_hasBound_definedBefore() async {
+ var unit = await checkFileElement(r'''
+class A<T extends int> {}
+A v = null;
+''');
+ checkElementText(
+ unit.library,
+ r'''
+class A<T extends int> {
+}
+A<int> v;
''');
- expect(unit.topLevelVariables[0].type.toString(), 'C<int>');
}
- test_instantiateToBounds_notGeneric() async {
+ test_instantiateToBounds_typeName_OK_noBound() async {
var unit = await checkFileElement(r'''
-class A {}
+class A<T> {}
class B<T extends A> {}
B v = null;
''');
- expect(unit.topLevelVariables[0].type.toString(), 'B<A>');
+ checkElementText(
+ unit.library,
+ r'''
+class A<T> {
+}
+class B<T extends A<dynamic>> {
+}
+B<A<dynamic>> v;
+''');
}
test_lambdaDoesNotHavePropagatedTypeHint() async {
@@ -5062,6 +5159,11 @@ class InferredTypeTest_Driver extends InferredTypeTest {
test_blockBodiedLambdas_noReturn_topLevel() =>
super.test_blockBodiedLambdas_noReturn_topLevel();
+ @override
+ test_instantiateToBounds_typeName_OK_hasBound_definedAfter() async {
+ await super.test_instantiateToBounds_typeName_OK_hasBound_definedAfter();
+ }
+
@failingTest
@override
test_listLiteralsCanInferNull_topLevel() =>

Powered by Google App Engine
This is Rietveld 408576698