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 ccc274f0367fc8e3018e303c230719e0c2cf25b1..b143a8355db7ecda72397a721780510e98e55874 100644 |
--- a/pkg/analyzer/test/src/task/strong_mode_test.dart |
+++ b/pkg/analyzer/test/src/task/strong_mode_test.dart |
@@ -458,6 +458,9 @@ class B extends A { |
var get $getterName => 1; |
} |
'''); |
+ ClassElement classA = unit.getType('A'); |
+ FieldElement fieldA = classA.getField(getterName); |
+ PropertyAccessorElement getterA = classA.getGetter(getterName); |
ClassElement classB = unit.getType('B'); |
FieldElement fieldB = classB.getField(getterName); |
PropertyAccessorElement getterB = classB.getGetter(getterName); |
@@ -466,8 +469,92 @@ class B extends A { |
inferrer.inferCompilationUnit(unit); |
+ // Expected behavior is that the getter is inferred: getters and setters |
+ // are treated as independent methods. |
+ expect(fieldB.type, fieldA.type); |
+ expect(getterB.returnType, getterA.returnType); |
+ } |
+ |
+ void test_inferCompilationUnit_setter_single() { |
+ InstanceMemberInferrer inferrer = createInferrer; |
+ String setterName = 'g'; |
+ CompilationUnitElement unit = resolve(''' |
+class A { |
+ set $setterName(int x) {} |
+} |
+class B extends A { |
+ set $setterName(x) {} |
+} |
+'''); |
+ ClassElement classA = unit.getType('A'); |
+ FieldElement fieldA = classA.getField(setterName); |
+ PropertyAccessorElement setterA = classA.getSetter(setterName); |
+ ClassElement classB = unit.getType('B'); |
+ FieldElement fieldB = classB.getField(setterName); |
+ PropertyAccessorElement setterB = classB.getSetter(setterName); |
expect(fieldB.type.isDynamic, isTrue); |
- expect(getterB.returnType.isDynamic, isTrue); |
+ expect(setterB.parameters[0].type.isDynamic, isTrue); |
+ |
+ inferrer.inferCompilationUnit(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> { |
+ set $setterName(E x) {} |
+} |
+class B<E> extends A<E> { |
+ set $setterName(x) {} |
+} |
+'''); |
+ ClassElement classB = unit.getType('B'); |
+ DartType typeBE = classB.typeParameters[0].type; |
+ FieldElement fieldB = classB.getField(setterName); |
+ PropertyAccessorElement setterB = classB.getSetter(setterName); |
+ expect(fieldB.type.isDynamic, isTrue); |
+ expect(setterB.parameters[0].type.isDynamic, isTrue); |
+ |
+ inferrer.inferCompilationUnit(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 { |
+ int get $getterName => 0; |
+ set $getterName(String value) {} |
+} |
+class B extends A { |
+ set $getterName(x) {} |
+} |
+'''); |
+ ClassElement classA = unit.getType('A'); |
+ FieldElement fieldA = classA.getField(getterName); |
+ PropertyAccessorElement setterA = classA.getSetter(getterName); |
+ ClassElement classB = unit.getType('B'); |
+ FieldElement fieldB = classB.getField(getterName); |
+ PropertyAccessorElement setterB = classB.getSetter(getterName); |
+ expect(fieldB.type.isDynamic, isTrue); |
+ expect(setterB.parameters[0].type.isDynamic, isTrue); |
+ |
+ inferrer.inferCompilationUnit(unit); |
+ |
+ // Expected behavior is that the getter is inferred: getters and setters |
+ // are treated as independent methods. |
+ expect(setterB.parameters[0].type, setterA.parameters[0].type); |
+ |
+ // Note that B's synthetic field type will be String. This matches what |
+ // resolver would do if we explicitly typed the parameter as 'String' |
+ expect(fieldB.type, setterB.parameters[0].type); |
} |
void test_inferCompilationUnit_invalid_inheritanceCycle() { |