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

Unified Diff: pkg/analyzer/lib/src/generated/static_type_analyzer.dart

Issue 1314793005: Strong mode local variable inference (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Make StrongModeTypePropagationTest a direct subclass of ResolverTestCase Created 5 years, 4 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/generated/engine.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/static_type_analyzer.dart
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index 096c14b0abb4c95b4f5ca10dea94c34e46698db6..720f8bbd4f0e314e7688cc267ac2ef22bfab6c7f 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -543,8 +543,10 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
}
}
}
- _recordStaticType(node, _typeProvider.mapType
- .substitute4(<DartType>[staticKeyType, staticValueType]));
+ _recordStaticType(
+ node,
+ _typeProvider.mapType
+ .substitute4(<DartType>[staticKeyType, staticValueType]));
return null;
}
@@ -1179,9 +1181,25 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
return null;
}
+ void _inferLocalVariableType(
+ VariableDeclaration node, Expression initializer) {
+ if (initializer != null &&
+ (node.parent as VariableDeclarationList).type == null &&
+ (node.element is LocalVariableElementImpl) &&
+ (initializer.staticType != null) &&
+ (!initializer.staticType.isBottom)) {
+ LocalVariableElementImpl element = node.element;
+ element.type = initializer.staticType;
+ node.name.staticType = initializer.staticType;
+ }
+ }
+
@override
Object visitVariableDeclaration(VariableDeclaration node) {
Expression initializer = node.initializer;
+ if (_resolver.definingLibrary.context.analysisOptions.strongMode) {
+ _inferLocalVariableType(node, initializer);
+ }
if (initializer != null) {
DartType rightType = initializer.bestType;
SimpleIdentifier name = node.name;
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698