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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.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 | « compiler/java/com/google/dart/compiler/type/Types.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
index 39797f3a86db5fbe87bbd5769e4d6e942db9a6f6..92c941d23c75d4a9478d7919a41cc47f7cda840a 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -2409,8 +2409,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
}
/**
- * When single variable has conflicting type constraints, right now we don't try to unify them,
- * instead we fall back to "dynamic".
+ * When single variable has conflicting type constraints, we use union of types.
*/
public void test_typesPropagation_ifIsType_conflictingTypes() throws Exception {
analyzeLibrary(
@@ -2421,7 +2420,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
" }",
"}",
"");
- assertInferredElementTypeString(testUnit, "v1", "dynamic");
+ assertInferredElementTypeString(testUnit, "v1", "[int, String]");
}
public void test_typesPropagation_ifIsType_negation() throws Exception {
@@ -2769,6 +2768,38 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
assertInferredElementTypeString(testUnit, "b3", "dynamic");
}
+ /**
+ * When variable has explicit type, we should not fall to 'dynamic', we need to keep this type.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=6399
+ */
+ public void test_typesPropagation_assertIsType_hasExplicitType() throws Exception {
+ analyzeLibrary(
+ "class A {}",
+ "class B extends A {}",
+ "class C extends B {}",
+ "main() {",
+ " B v;",
+ " if (v is A) {",
+ " var v1 = v;",
+ " }",
+ " if (v is B) {",
+ " var v2 = v;",
+ " }",
+ " if (v is C) {",
+ " var v3 = v;",
+ " }",
+ " if (v is String) {",
+ " var v4 = v;",
+ " }",
+ "}",
+ "");
+ assertInferredElementTypeString(testUnit, "v1", "B");
+ assertInferredElementTypeString(testUnit, "v2", "B");
+ assertInferredElementTypeString(testUnit, "v3", "C");
+ assertInferredElementTypeString(testUnit, "v4", "[B, String]");
+ }
+
public void test_typesPropagation_field_inClass_final() throws Exception {
analyzeLibrary(
"// filler filler filler filler filler filler filler filler filler filler",
« no previous file with comments | « compiler/java/com/google/dart/compiler/type/Types.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698