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

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: 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..bc49eaa97d0b4b469fab50de7ee1310d694fbafd 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,30 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
return null;
}
+ void _inferLocalVariableType(
+ VariableDeclaration node, Expression initializer) {
+ if (initializer == null) return;
Brian Wilkerson 2015/08/26 22:19:25 nit: we have a group style of never using non-bloc
Leaf 2015/08/26 22:25:52 Ok. Do you guys have a preferred style for this i
Brian Wilkerson 2015/08/26 23:10:28 Nope. Whichever you think is more readable.
+ if ((node.parent as VariableDeclarationList).type != null) return;
+ if (node.element is! LocalVariableElement) return;
+ LocalVariableElement element = node.element;
+ if (initializer.staticType == null) return;
+ if (initializer.staticType == _typeProvider.bottomType) return;
+ element.type = initializer.staticType;
+ node.name.staticType = initializer.staticType;
+ if (element is PropertyInducingElement) {
+ element.getter.returnType = type;
+ if (!element.isFinal && !element.isConst) {
+ element.setter.parameters[0].type = type;
+ }
+ }
+ }
+
@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