Index: pkg/analyzer/lib/src/task/strong_mode.dart |
diff --git a/pkg/analyzer/lib/src/task/strong_mode.dart b/pkg/analyzer/lib/src/task/strong_mode.dart |
index f8cb97f6e8964224c15fbab6d0fdc2a9993c3bae..208521f061f47cae0a054108792b76974e723f67 100644 |
--- a/pkg/analyzer/lib/src/task/strong_mode.dart |
+++ b/pkg/analyzer/lib/src/task/strong_mode.dart |
@@ -294,10 +294,15 @@ class InstanceMemberInferrer { |
} |
} |
// |
- // Then, if none was found, infer the type from the initialization |
- // expression. |
+ // If there is no overridden getter or if the overridden getter's type is |
+ // dynamic, then we can infer the type from the initialization expression |
+ // without breaking subtype rules. We could potentially infer a consistent |
+ // return type even if the overridden getter's type was not dynamic, but |
+ // choose not to for simplicity. The field is required to be final to |
+ // prevent choosing a type that is inconsistent with assignments we cannot |
+ // analyze. |
// |
- if (newType == null) { |
+ if (newType == null || newType.isDynamic) { |
if (fieldElement.initializer != null && |
(fieldElement.isFinal || overriddenGetters.isEmpty)) { |
newType = fieldElement.initializer.returnType; |