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

Unified Diff: pkg/analyzer/lib/src/task/strong_mode.dart

Issue 1367183004: analyzer strong mode: infer final field from initializer if super getters are dynamic (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: redo comment per Brian's suggestion Created 5 years, 3 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong_mode_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong_mode_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698