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

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

Issue 10829292: Issue 4410. Infer types using 'assert' statement (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
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 600bdf35431580125fa6f113cd4bde8d8601a036..7c081704c11bf8c170b32139bd4b75007b65a03b 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -2210,6 +2210,36 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
assertInferredElementTypeString(testUnit, "v1", "String");
}
+ /**
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=4410
+ */
+ public void test_typesPropagation_assertIsType() throws Exception {
+ analyzeLibrary(
+ "f(var v) {",
+ " if (true) {",
+ " var v1 = v;",
+ " assert(v is String);",
+ " var v2 = v;",
+ " {",
+ " var v3 = v;",
+ " }",
+ " var v4 = v;",
+ " }",
+ " var v5 = v;",
+ "}",
+ "");
+ // we don't know type initially
+ assertInferredElementTypeString(testUnit, "v1", "<dynamic>");
+ // after "assert" all next statements know type
+ assertInferredElementTypeString(testUnit, "v2", "String");
+ assertInferredElementTypeString(testUnit, "v3", "String");
+ // type is set to unknown only when we exit control Block, not just any Block
+ assertInferredElementTypeString(testUnit, "v4", "String");
+ // we exited "if" Block, so "assert" may be was not executed, so we don't know type
+ assertInferredElementTypeString(testUnit, "v5", "<dynamic>");
+ }
+
public void test_typesPropagation_field_inClass_final() throws Exception {
analyzeLibrary(
"// filler filler filler filler filler filler filler filler filler filler",

Powered by Google App Engine
This is Rietveld 408576698