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

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

Issue 10870058: Use intersection of types as type of conditional (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 581c4430bf1973d678cb860cac06a635bb858d40..954c764c03f1701747edc44fbd56d5e04cad33e3 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -2573,6 +2573,49 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
"");
assertInferredElementTypeString(testUnit, "v", "Event");
}
+
+ /**
+ * Helpful (but not perfectly satisfying Specification) type of "conditional" is intersection of
+ * then/else types, not just their "least upper bounds". And this corresponds runtime behavior.
+ */
+ public void test_typesPropagation_conditional() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "interface I1 {",
+ " f1();",
+ "}",
+ "interface I2 {",
+ " f2();",
+ "}",
+ "class A implements I1, I2 {",
+ " f1() => 11;",
+ " f2() => 12;",
+ "}",
+ "class B implements I1, I2 {",
+ " f1() => 21;",
+ " f2() => 22;",
+ "}",
+ "main() {",
+ " var v = true ? new A() : new B();",
+ " v.f1();",
+ " v.f2();",
+ "}",
+ "");
+ // no errors, because both f1() and f2() invocations were resolved
+ assertErrors(libraryResult.getErrors());
+ // v.f1() was resolved
+ {
+ DartExpression expression = findExpression(testUnit, "v.f1()");
+ assertNotNull(expression);
+ assertNotNull(expression.getElement());
+ }
+ // v.f2() was resolved
+ {
+ DartExpression expression = findExpression(testUnit, "v.f1()");
+ assertNotNull(expression);
+ assertNotNull(expression.getElement());
+ }
+ }
public void test_getType_binaryExpression() throws Exception {
analyzeLibrary(
« 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