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

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

Issue 1036233006: Issue 20144. Reset propagated type if one of the 'if' branches changes it to a different one. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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/generated/resolver_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/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index c81696867d9538d39c28f23f7ce8ad095de64a38..d4c1034df62c157e47c908f9fac5c552d6f96750 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -10969,12 +10969,14 @@ class ResolverVisitor extends ScopedVisitor {
_propagateFalseState(condition);
_overrideManager.applyOverrides(elseOverrides);
} else if (!thenIsAbrupt && !elseIsAbrupt) {
+ List<Map<VariableElement, DartType>> perBranchOverrides =
+ new List<Map<VariableElement, DartType>>();
+ perBranchOverrides.add(thenOverrides);
+ perBranchOverrides.add(elseOverrides);
if (AnalysisEngine.instance.enableUnionTypes) {
- List<Map<VariableElement, DartType>> perBranchOverrides =
- new List<Map<VariableElement, DartType>>();
- perBranchOverrides.add(thenOverrides);
- perBranchOverrides.add(elseOverrides);
_overrideManager.joinOverrides(perBranchOverrides);
+ } else {
+ _overrideManager.mergeOverrides(perBranchOverrides);
}
}
return null;
@@ -12776,6 +12778,24 @@ class TypeOverrideManager {
}
/**
+ * Update overrides assuming [perBranchOverrides] is the collection of
+ * per-branch overrides for *all* branches flowing into a join point.
+ *
+ * If a variable type in any of branches is not the same as its type before
+ * the branching, then its propagated type is reset to `null`.
+ */
+ void mergeOverrides(List<Map<VariableElement, DartType>> perBranchOverrides) {
+ for (Map<VariableElement, DartType> branch in perBranchOverrides) {
+ branch.forEach((VariableElement variable, DartType branchType) {
+ DartType currentType = _currentScope.getType(variable);
+ if (currentType != branchType) {
+ _currentScope.resetType(variable);
+ }
+ });
+ }
+ }
+
+ /**
* Set the overridden type of the given element to the given type
*
* @param element the element whose type might have been overridden
@@ -12862,9 +12882,12 @@ class TypeOverrideManager_TypeOverrideScope {
* @return the overridden type of the given element
*/
DartType getType(Element element) {
+ if (element is PropertyAccessorElement) {
+ element = (element as PropertyAccessorElement).variable;
+ }
DartType type = _overridenTypes[element];
- if (type == null && element is PropertyAccessorElement) {
- type = _overridenTypes[element.variable];
+ if (_overridenTypes.containsKey(element)) {
+ return type;
}
if (type != null) {
return type;
@@ -12875,6 +12898,13 @@ class TypeOverrideManager_TypeOverrideScope {
}
/**
+ * Clears the overridden type of the given [element].
+ */
+ void resetType(VariableElement element) {
+ _overridenTypes[element] = null;
+ }
+
+ /**
* Set the overridden type of the given element to the given type
*
* @param element the element whose type might have been overridden
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698