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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java

Issue 10434008: Use most specific inferred type, or fall back to Dynamic (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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
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 e085cf2bd0b5148bd8678166b37486b144623fdc..719a8fca75fb63d17182754f8f46f095b37ac762 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -1205,13 +1205,38 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
*/
public void test_typesPropagation_ifIsType_mostSpecific() throws Exception {
AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "f() {",
+ " int a;",
+ " num b;",
+ " if (a is num) {",
+ " var a1 = a;",
+ " }",
+ " if (a is Dynamic) {",
+ " var a2 = a;",
+ " }",
+ " if (b is int) {",
+ " var b1 = b;",
+ " }",
+ "}",
+ "");
+ assertVariableTypeString(libraryResult, "a1", "int");
+ assertVariableTypeString(libraryResult, "a2", "int");
+ assertVariableTypeString(libraryResult, "b1", "int");
+ }
+
+ /**
+ * When single variable has conflicting type constraints, right now we don't try to unify them,
+ * instead we fall back to "Dynamic".
+ */
+ public void test_typesPropagation_ifIsType_conflictingTypes() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
"f(int v) {",
- " if (v is num) {",
+ " if (v is String) {",
" var v1 = v;",
" }",
"}",
"");
- assertVariableTypeString(libraryResult, "v1", "int");
+ assertVariableTypeString(libraryResult, "v1", "<dynamic>");
}
public void test_typesPropagation_ifIsType_negation() throws Exception {

Powered by Google App Engine
This is Rietveld 408576698