Chromium Code Reviews| 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 |