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

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

Issue 2754423002: Fail inference when an instance field is referenced. (Closed)
Patch Set: Clean up and move tests. 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
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_const_expr.dart ('k') | pkg/analyzer/lib/src/task/strong_mode.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/dart.dart
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index 2a7ca939ddf6115b8c4544196a0960d2ff649843..4635f5542c68f754d0f2618d065837092fcae6f0 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -3462,6 +3462,30 @@ class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask {
//
CompilationUnit unit = getRequiredInput(UNIT_INPUT);
TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
+
+ //
+ // Prepare fields for which inference should be disabled.
+ //
+ Set<FieldElement> fieldsWithDisabledInference = new Set<FieldElement>();
+ for (CompilationUnitMember classDeclaration in unit.declarations) {
+ if (classDeclaration is ClassDeclaration) {
+ for (ClassMember fieldDeclaration in classDeclaration.members) {
+ if (fieldDeclaration is FieldDeclaration) {
+ if (!fieldDeclaration.isStatic) {
+ for (VariableDeclaration field
+ in fieldDeclaration.fields.variables) {
+ Expression initializer = field.initializer;
+ if (initializer != null &&
+ !isValidForTypeInference(initializer)) {
+ fieldsWithDisabledInference.add(field.element);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
//
// Infer instance members.
//
@@ -3470,6 +3494,7 @@ class InferInstanceMembersInUnitTask extends SourceBasedAnalysisTask {
typeProvider,
new InheritanceManager(
resolutionMap.elementDeclaredByCompilationUnit(unit).library),
+ fieldsWithDisabledInference,
typeSystem: context.typeSystem);
inferrer.inferCompilationUnit(unit.element);
}
@@ -3742,13 +3767,19 @@ class InferStaticVariableTypeTask extends InferStaticVariableTask {
visitor.initForIncrementalResolution();
initializer.accept(visitor);
+ DartType newType;
+ if (!isValidForTypeInference(initializer)) {
+ newType = typeProvider.dynamicType;
+ } else {
+ newType = initializer.staticType;
+ if (newType == null || newType.isBottom || newType.isDartCoreNull) {
+ newType = typeProvider.dynamicType;
+ }
+ }
+
//
// Record the type of the variable.
//
- DartType newType = initializer.staticType;
- if (newType == null || newType.isBottom || newType.isDartCoreNull) {
- newType = typeProvider.dynamicType;
- }
setFieldType(variable, newType);
errors = getUniqueErrors(errorListener.errors);
} else {
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_const_expr.dart ('k') | pkg/analyzer/lib/src/task/strong_mode.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698