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

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

Issue 1405803003: Fix loop var inference when iterating on a type-param type. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Added extra test Created 5 years, 2 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 | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_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 7362c4de016b5baacdaf6d352a1cd2f69afa72a6..ce0016c586a00465e31f1085c06f825d7d10cc41 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -1419,12 +1419,17 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
}
// TODO(vsm): Use leafp's matchType here?
- DartType _findIteratedType(InterfaceType type, DartType targetType) {
+ DartType _findIteratedType(DartType type, DartType targetType) {
// Set by _find if match is found
DartType result = null;
// Elements we've already visited on a given inheritance path.
HashSet<ClassElement> visitedClasses = null;
+ while (type is TypeParameterType) {
+ TypeParameterElement element = type.element;
+ type = element.bound;
+ }
+
bool _find(InterfaceType type) {
ClassElement element = type.element;
if (type == _typeProvider.objectType || element == null) {
@@ -1451,7 +1456,9 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
visitedClasses.remove(element);
}
}
- _find(type);
+ if (type is InterfaceType) {
+ _find(type);
+ }
return result;
}
@@ -1691,15 +1698,13 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
Expression expr = loop.iterable;
LocalVariableElementImpl element = loopVariable.element;
DartType exprType = expr.staticType;
- if (exprType is InterfaceType) {
- DartType targetType = (loop.awaitKeyword == null)
- ? _typeProvider.iterableType
+ DartType targetType = (loop.awaitKeyword == null)
+ ? _typeProvider.iterableType
: _typeProvider.streamType;
- DartType iteratedType = _findIteratedType(exprType, targetType);
- if (element != null && iteratedType != null) {
- element.type = iteratedType;
- loopVariable.identifier.staticType = iteratedType;
- }
+ DartType iteratedType = _findIteratedType(exprType, targetType);
+ if (element != null && iteratedType != null) {
+ element.type = iteratedType;
+ loopVariable.identifier.staticType = iteratedType;
}
}
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698