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

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

Issue 971193003: Don't set a propagate type if the variable has already the same static type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 10e6f6b38d342767d4c3be7efef77c0f0fc7ab49..ebbf5edea4d5178d6a1abf9824088760f1b17ee1 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -1282,10 +1282,12 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
if (initializer != null) {
DartType rightType = initializer.bestType;
SimpleIdentifier name = node.name;
- _recordPropagatedType(name, rightType);
VariableElement element = name.staticElement as VariableElement;
if (element != null) {
_resolver.overrideVariable(element, rightType, true);
+ if (_isReallyMoreSpecificThan(rightType, element.type)) {
Brian Wilkerson 2015/03/03 14:53:49 Shouldn't this test be moved into _recordPropagate
scheglov 2015/03/03 15:02:17 Maybe. It takes Expression, so we would need to ad
+ _recordPropagatedType(name, rightType);
+ }
}
}
return null;
@@ -1880,6 +1882,22 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
map["video"] = "VideoElement";
return map;
}
+
+ /**
+ * Return `true` if [propagatedType] is more specific than [staticType].
+ * In addition to [DartType.isMoreSpecificThan], we need to check that
+ * [propagatedType] is not the same as [staticType].
+ */
+ static bool _isReallyMoreSpecificThan(
+ DartType propagatedType, DartType staticType) {
+ if (propagatedType == null) {
+ return false;
+ }
+ if (propagatedType == staticType) {
+ return false;
+ }
+ return propagatedType.isMoreSpecificThan(staticType);
+ }
}
class _StaticTypeAnalyzer_computePropagatedReturnTypeOfFunction

Powered by Google App Engine
This is Rietveld 408576698