Index: pkg/analyzer/test/src/task/strong_mode_test.dart |
diff --git a/pkg/analyzer/test/src/task/strong_mode_test.dart b/pkg/analyzer/test/src/task/strong_mode_test.dart |
index b7b86e3983ccce4a2f442d588836c9b3acb74561..c4589f789c0a1c76f95e1442c778c27dbb228a7b 100644 |
--- a/pkg/analyzer/test/src/task/strong_mode_test.dart |
+++ b/pkg/analyzer/test/src/task/strong_mode_test.dart |
@@ -7,6 +7,7 @@ library analyzer.test.src.task.strong_mode_test; |
import 'package:analyzer/dart/ast/ast.dart'; |
import 'package:analyzer/dart/element/element.dart'; |
import 'package:analyzer/dart/element/type.dart'; |
+import 'package:analyzer/src/generated/resolver.dart'; |
import 'package:analyzer/src/generated/source.dart'; |
import 'package:analyzer/src/task/strong_mode.dart'; |
import 'package:unittest/unittest.dart'; |
@@ -24,9 +25,11 @@ main() { |
@reflectiveTest |
class InstanceMemberInferrerTest extends AbstractContextTest { |
- InstanceMemberInferrer get createInferrer => |
- new InstanceMemberInferrer(context.typeProvider, |
- typeSystem: context.typeSystem); |
+ InstanceMemberInferrer createInferrer(LibraryElement library) { |
+ return new InstanceMemberInferrer( |
+ context.typeProvider, new InheritanceManager(library), |
+ typeSystem: context.typeSystem); |
+ } |
/** |
* Add a source with the given [content] and return the result of resolving |
@@ -38,13 +41,12 @@ class InstanceMemberInferrerTest extends AbstractContextTest { |
} |
void test_creation() { |
- InstanceMemberInferrer inferrer = createInferrer; |
+ InstanceMemberInferrer inferrer = createInferrer(null); |
expect(inferrer, isNotNull); |
expect(inferrer.typeSystem, isNotNull); |
} |
void test_inferCompilationUnit_field_multiple_different() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -63,14 +65,13 @@ class C implements A, B { |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_field_multiple_different_generic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A<E> { |
@@ -89,14 +90,13 @@ class C implements A<int>, B<double> { |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_field_multiple_dynamic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -115,14 +115,13 @@ class C implements A, B { |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_field_multiple_same() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -144,14 +143,13 @@ class C implements A, B { |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldC.type, expectedType); |
expect(getterC.returnType, expectedType); |
} |
void test_inferCompilationUnit_field_noOverride() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -164,7 +162,7 @@ class A { |
expect(fieldA.type.isDynamic, isTrue); |
expect(getterA.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ InstanceMemberInferrer inferrer = _runInferrer(unit); |
DartType intType = inferrer.typeProvider.intType; |
expect(fieldA.type, intType); |
@@ -172,7 +170,6 @@ class A { |
} |
void test_inferCompilationUnit_field_noOverride_bottom() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -185,14 +182,13 @@ class A { |
expect(fieldA.type.isDynamic, isTrue); |
expect(getterA.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldA.type.isDynamic, isTrue); |
expect(getterA.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_field_single_explicitlyDynamic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -211,14 +207,13 @@ class B extends A { |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldB.type, fieldA.type); |
expect(getterB.returnType, getterA.returnType); |
} |
void test_inferCompilationUnit_field_single_final() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -237,14 +232,13 @@ class B extends A { |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldB.type, fieldA.type); |
expect(getterB.returnType, getterA.returnType); |
} |
void test_inferCompilationUnit_field_single_final_narrowType() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -260,14 +254,13 @@ class B extends A { |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ InstanceMemberInferrer inferrer = _runInferrer(unit); |
expect(fieldB.type, inferrer.typeProvider.intType); |
expect(getterB.returnType, fieldB.type); |
} |
void test_inferCompilationUnit_field_single_generic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A<E> { |
@@ -284,14 +277,13 @@ class B<E> extends A<E> { |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldB.type, typeBE); |
expect(getterB.returnType, typeBE); |
} |
void test_inferCompilationUnit_field_single_inconsistentAccessors() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -308,14 +300,13 @@ class B extends A { |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_field_single_noModifiers() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -334,14 +325,13 @@ class B extends A { |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldB.type, fieldA.type); |
expect(getterB.returnType, getterA.returnType); |
} |
void test_inferCompilationUnit_fieldFormal() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String fieldName = 'f'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -356,7 +346,7 @@ class A { |
expect(fieldA.type.isDynamic, isTrue); |
expect(paramA.type.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ InstanceMemberInferrer inferrer = _runInferrer(unit); |
DartType intType = inferrer.typeProvider.intType; |
expect(fieldA.type, intType); |
@@ -364,7 +354,6 @@ class A { |
} |
void test_inferCompilationUnit_getter_multiple_different() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String getterName = 'g'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -383,14 +372,13 @@ class C implements A, B { |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_getter_multiple_dynamic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String getterName = 'g'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -409,14 +397,13 @@ class C implements A, B { |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_getter_multiple_same() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String getterName = 'g'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -438,14 +425,13 @@ class C implements A, B { |
expect(fieldC.type.isDynamic, isTrue); |
expect(getterC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldC.type, expectedType); |
expect(getterC.returnType, expectedType); |
} |
void test_inferCompilationUnit_getter_single() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String getterName = 'g'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -464,14 +450,13 @@ class B extends A { |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldB.type, fieldA.type); |
expect(getterB.returnType, getterA.returnType); |
} |
void test_inferCompilationUnit_getter_single_generic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String getterName = 'g'; |
CompilationUnitElement unit = resolve(''' |
class A<E> { |
@@ -488,14 +473,13 @@ class B<E> extends A<E> { |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldB.type, typeBE); |
expect(getterB.returnType, typeBE); |
} |
void test_inferCompilationUnit_getter_single_inconsistentAccessors() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String getterName = 'g'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -515,7 +499,7 @@ class B extends A { |
expect(fieldB.type.isDynamic, isTrue); |
expect(getterB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
// Expected behavior is that the getter is inferred: getters and setters |
// are treated as independent methods. |
@@ -524,17 +508,15 @@ class B extends A { |
} |
void test_inferCompilationUnit_invalid_inheritanceCycle() { |
- InstanceMemberInferrer inferrer = createInferrer; |
CompilationUnitElement unit = resolve(''' |
class A extends C {} |
class B extends A {} |
class C extends B {} |
'''); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
} |
void test_inferCompilationUnit_method_parameter_multiple_different() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -552,13 +534,12 @@ class C implements A, B { |
ParameterElement parameterC = methodC.parameters[0]; |
expect(parameterC.type.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(parameterC.type.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_method_parameter_multiple_named_different() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -576,13 +557,12 @@ class C implements A, B { |
ParameterElement parameterC = methodC.parameters[0]; |
expect(parameterC.type.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(parameterC.type.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_method_parameter_multiple_named_same() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -604,13 +584,12 @@ class C implements A, B { |
ParameterElement parameterC = methodC.parameters[0]; |
expect(parameterC.type.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(parameterC.type, expectedType); |
} |
void test_inferCompilationUnit_method_parameter_multiple_namedAndRequired() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -628,14 +607,13 @@ class C implements A, B { |
ParameterElement parameterC = methodC.parameters[0]; |
expect(parameterC.type.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(parameterC.type.isDynamic, isTrue); |
} |
void |
test_inferCompilationUnit_method_parameter_multiple_optionalAndRequired() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -657,13 +635,12 @@ class C implements A, B { |
ParameterElement parameterC = methodC.parameters[0]; |
expect(parameterC.type.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(parameterC.type, expectedType); |
} |
void test_inferCompilationUnit_method_parameter_single_generic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A<E> { |
@@ -680,7 +657,7 @@ class C<E> implements A<E> { |
expect(parameterC.type.isDynamic, isTrue); |
expect(methodC.type.typeArguments, [typeCE]); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(parameterC.type, classC.typeParameters[0].type); |
expect(methodC.type.typeArguments, [typeCE], |
@@ -688,7 +665,6 @@ class C<E> implements A<E> { |
} |
void test_inferCompilationUnit_method_return_multiple_different() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -705,13 +681,12 @@ class C implements A, B { |
MethodElement methodC = classC.getMethod(methodName); |
expect(methodC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(methodC.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_method_return_multiple_different_generic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A<E> { |
@@ -728,13 +703,12 @@ class C implements A<int>, B<double> { |
MethodElement methodC = classC.getMethod(methodName); |
expect(methodC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(methodC.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_method_return_multiple_dynamic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -751,13 +725,12 @@ class C implements A, B { |
MethodElement methodC = classC.getMethod(methodName); |
expect(methodC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(methodC.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_method_return_multiple_same_generic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A<E> { |
@@ -774,13 +747,12 @@ class C<E> implements A<E>, B<E> { |
MethodElement methodC = classC.getMethod(methodName); |
expect(methodC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(methodC.returnType, classC.typeParameters[0].type); |
} |
void test_inferCompilationUnit_method_return_multiple_same_nonVoid() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -800,13 +772,12 @@ class C implements A, B { |
MethodElement methodC = classC.getMethod(methodName); |
expect(methodC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(methodC.returnType, expectedType); |
} |
void test_inferCompilationUnit_method_return_multiple_same_void() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -826,13 +797,12 @@ class C implements A, B { |
MethodElement methodC = classC.getMethod(methodName); |
expect(methodC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(methodC.returnType, expectedType); |
} |
void test_inferCompilationUnit_method_return_multiple_void() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -849,13 +819,12 @@ class C implements A, B { |
MethodElement methodC = classC.getMethod(methodName); |
expect(methodC.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(methodC.returnType.isDynamic, isTrue); |
} |
void test_inferCompilationUnit_method_return_single() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -871,13 +840,12 @@ class B extends A { |
MethodElement methodB = classB.getMethod(methodName); |
expect(methodB.returnType.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(methodB.returnType, methodA.returnType); |
} |
void test_inferCompilationUnit_method_return_single_generic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String methodName = 'm'; |
CompilationUnitElement unit = resolve(''' |
class A<E> { |
@@ -893,7 +861,7 @@ class B<E> extends A<E> { |
expect(methodB.returnType.isDynamic, isTrue); |
expect(methodB.type.typeArguments, [typeBE]); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(methodB.returnType, classB.typeParameters[0].type); |
expect(methodB.type.typeArguments, [typeBE], |
@@ -901,7 +869,6 @@ class B<E> extends A<E> { |
} |
void test_inferCompilationUnit_setter_single() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String setterName = 'g'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -920,14 +887,13 @@ class B extends A { |
expect(fieldB.type.isDynamic, isTrue); |
expect(setterB.parameters[0].type.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldB.type, fieldA.type); |
expect(setterB.parameters[0].type, setterA.parameters[0].type); |
} |
void test_inferCompilationUnit_setter_single_generic() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String setterName = 'g'; |
CompilationUnitElement unit = resolve(''' |
class A<E> { |
@@ -944,14 +910,13 @@ class B<E> extends A<E> { |
expect(fieldB.type.isDynamic, isTrue); |
expect(setterB.parameters[0].type.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
expect(fieldB.type, typeBE); |
expect(setterB.parameters[0].type, typeBE); |
} |
void test_inferCompilationUnit_setter_single_inconsistentAccessors() { |
- InstanceMemberInferrer inferrer = createInferrer; |
String getterName = 'g'; |
CompilationUnitElement unit = resolve(''' |
class A { |
@@ -970,7 +935,7 @@ class B extends A { |
expect(fieldB.type.isDynamic, isTrue); |
expect(setterB.parameters[0].type.isDynamic, isTrue); |
- inferrer.inferCompilationUnit(unit); |
+ _runInferrer(unit); |
// Expected behavior is that the getter is inferred: getters and setters |
// are treated as independent methods. |
@@ -980,6 +945,12 @@ class B extends A { |
// resolver would do if we explicitly typed the parameter as 'String' |
expect(fieldB.type, setterB.parameters[0].type); |
} |
+ |
+ InstanceMemberInferrer _runInferrer(CompilationUnitElement unit) { |
+ InstanceMemberInferrer inferrer = createInferrer(unit.library); |
+ inferrer.inferCompilationUnit(unit); |
+ return inferrer; |
+ } |
} |
@reflectiveTest |