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

Unified Diff: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java

Issue 11271041: Issue 6399. Don't fall back to 'dynamic' when variable has explicit type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use union of types Created 8 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 | compiler/java/com/google/dart/compiler/type/Types.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
diff --git a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
index ba5e65a64ef635cc6d4d698b14db88f43f391825..8aee54083670c0dd12cd5bea457322354c026cba 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -774,7 +774,9 @@ public class TypeAnalyzer implements DartCompilationPhase {
// if we fell back to Dynamic, keep it
} else {
Type unionType = getUnionType(currentType, inferredType);
- unionType = Types.makeInferred(unionType);
+ if (unionType != currentType) {
+ unionType = Types.makeInferred(unionType);
+ }
blockOldTypes.getFirst().rememberOldType(element, element.getType());
Elements.setType(element, unionType);
}
@@ -785,21 +787,25 @@ public class TypeAnalyzer implements DartCompilationPhase {
* @return the {@link Type} which is both "a" and "b" types. May be "dynamic" if "a" and "b"
* don't form hierarchy.
*/
- Type getUnionType(Type a, Type b) {
- if (TypeKind.of(a) == TypeKind.DYNAMIC) {
- return b;
+ Type getUnionType(Type curType, Type newType) {
+ if (TypeKind.of(curType) == TypeKind.DYNAMIC) {
+ return newType;
}
- if (TypeKind.of(b) == TypeKind.DYNAMIC) {
- return a;
+ if (TypeKind.of(newType) == TypeKind.DYNAMIC) {
+ return curType;
}
- if (types.isSubtype(a, b)) {
- return a;
+ if (types.isSubtype(curType, newType)) {
+ return curType;
}
- if (types.isSubtype(b, a)) {
- return b;
+ if (types.isSubtype(newType, curType)) {
+ return newType;
}
- // TODO(scheglov) return union of types, but this is not easy
- return dynamicType;
+ // if InterfaceType, use union
+ if (curType instanceof InterfaceType && newType instanceof InterfaceType) {
+ return types.unionTypes(ImmutableList.of((InterfaceType) curType, (InterfaceType) newType));
+ }
+ // keep type as is
+ return curType;
}
void restore() {
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/type/Types.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698