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

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

Issue 1370793002: Improve the handling of inference for instance fields in the task model (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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
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 a21d94b70519b7b6902aa364ae243d1fbcc77310..b77e1cbdce00d58d759f149bb2f16cf999cd2f55 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -2667,35 +2667,32 @@ class InferStaticVariableTypeTask extends InferStaticVariableTask {
// have types inferred before inferring the type of this variable.
//
VariableElementImpl variable = target;
+
CompilationUnit unit = getRequiredInput(UNIT_INPUT);
TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);
RecordingErrorListener errorListener = new RecordingErrorListener();
- if (dependencyCycle == null) {
- //
- // Re-resolve the variable's initializer so that the inferred types of other
- // variables will be propagated.
- //
- NodeLocator locator = new NodeLocator(variable.nameOffset);
- AstNode node = locator.searchWithin(unit);
- VariableDeclaration declaration = node
- .getAncestor((AstNode ancestor) => ancestor is VariableDeclaration);
- if (declaration == null || declaration.name != node) {
- throw new AnalysisException(
- "NodeLocator failed to find a variable's declaration");
- }
- Expression initializer = declaration.initializer;
- ResolutionEraser.erase(initializer, eraseDeclarations: false);
- ResolutionContext resolutionContext =
- ResolutionContextBuilder.contextFor(initializer, errorListener);
- ResolverVisitor visitor = new ResolverVisitor(
- variable.library, variable.source, typeProvider, errorListener,
- nameScope: resolutionContext.scope);
- if (resolutionContext.enclosingClassDeclaration != null) {
- visitor.prepareToResolveMembersInClass(
- resolutionContext.enclosingClassDeclaration);
- }
- visitor.initForIncrementalResolution();
- initializer.accept(visitor);
+ VariableDeclaration declaration = getDeclaration(unit);
+ //
+ // Re-resolve the variable's initializer so that the inferred types of other
+ // variables will be propagated.
+ //
+ Expression initializer = declaration.initializer;
+ ResolutionEraser.erase(initializer, eraseDeclarations: false);
+ ResolutionContext resolutionContext =
+ ResolutionContextBuilder.contextFor(initializer, errorListener);
+ ResolverVisitor visitor = new ResolverVisitor(
+ variable.library, variable.source, typeProvider, errorListener,
+ nameScope: resolutionContext.scope);
+ if (resolutionContext.enclosingClassDeclaration != null) {
+ visitor.prepareToResolveMembersInClass(
+ resolutionContext.enclosingClassDeclaration);
+ }
+ visitor.initForIncrementalResolution();
+ initializer.accept(visitor);
+
+ // If we're not in a dependency cycle, and we have no type annotation,
+ // do inference.
+ if (dependencyCycle == null && variable.hasImplicitType) {
//
// Record the type of the variable.
//

Powered by Google App Engine
This is Rietveld 408576698