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

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: Address comments, add test, fix analyzer warnings 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
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..9415881cfd25ad1d9dc02e69277d50908e51bd8a 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 != _typeProvider.bottomType)) {
Paul Berry 2015/08/27 01:28:11 Nit: use initializer.staticType.isBottom.
Leaf 2015/08/27 18:15:26 Done.
+ 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;

Powered by Google App Engine
This is Rietveld 408576698