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

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

Issue 10869060: Infer type of List and Map literals (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 d2c58b6599818fe4c82352101b01348c9c51faa9..76884f63647c88b3e2a6448be5004faf905690a2 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -2777,6 +2777,54 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
}
}
+ public void test_typesPropagation_arrayLiteral_singleType() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " var a = [1, 2, 3];",
+ " var v = a[0];",
+ "}",
+ "");
+ assertErrors(libraryResult.getErrors());
+ assertInferredElementTypeString(testUnit, "v", "int");
+ }
+
+ public void test_typesPropagation_arrayLiteral_mixedTypes() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " var a = [1, 2, '3'];",
+ " var v = a[0];",
+ "}",
+ "");
+ assertErrors(libraryResult.getErrors());
+ assertInferredElementTypeString(testUnit, "v", "[Comparable, Hashable]");
+ }
+
+ public void test_typesPropagation_mapLiteral_singleType() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " var m = {'1': 1, '2' : 2, '3' : 3};",
+ " var v = m['1'];",
+ "}",
+ "");
+ assertErrors(libraryResult.getErrors());
+ assertInferredElementTypeString(testUnit, "v", "int");
+ }
+
+ public void test_typesPropagation_mapLiteral_mixedTypes() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " var m = {'1': 1, '2' : 2, '3' : 3.0};",
+ " var v = m['1'];",
+ "}",
+ "");
+ assertErrors(libraryResult.getErrors());
+ assertInferredElementTypeString(testUnit, "v", "num");
+ }
+
public void test_getType_binaryExpression() throws Exception {
analyzeLibrary(
"f(var arg) {",

Powered by Google App Engine
This is Rietveld 408576698