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

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

Issue 10540114: Issue 3528. Additional checks for 'case expressions' (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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 556cc154177ec5cb1778c1abb29237d463aabfca..bc9d1b6b1c11a63809bf3edd2e7d886ff55c8c31 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -163,25 +163,74 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
}
/**
+ * It is a static warning if the type of "switch expression" may not be assigned to the type of
+ * "case expression".
* <p>
* http://code.google.com/p/dart/issues/detail?id=3269
*/
- public void test_switchExpression_case_typeMismatch() throws Exception {
+ public void test_switchExpression_case_switchTypeMismatch() throws Exception {
AnalyzeLibraryResult libraryResult = analyzeLibrary(
"// filler filler filler filler filler filler filler filler filler filler",
"main() {",
" int v = 1;",
" switch (v) {",
" case 0: break;",
+ " }",
+ " switch (v) {",
+ " case 'a': break;",
+ " }",
+ "}",
+ "");
+ assertErrors(
+ libraryResult.getErrors(),
+ errEx(TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE, 8, 10, 3));
+ }
+
+ /**
+ * It is a compile-time error if the values of the case expressions do not all have the same type.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=3528
+ */
+ public void test_switchExpression_case_notIntString() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " var v = 1;",
+ " switch (v) {",
Brian Wilkerson 2012/06/12 14:58:50 The first two switch statements are not necessary
+ " case 0: break;",
+ " }",
+ " switch (v) {",
+ " case '0': break;",
+ " }",
+ " switch (v) {",
+ " case 0.0: break;",
+ " }",
+ "}",
+ "");
+ assertErrors(
+ libraryResult.getErrors(),
+ errEx(TypeErrorCode.CASE_EXPRESSION_SHOULD_BE_INT_STRING, 11, 10, 3));
+ }
+
+ /**
+ * It is a compile-time error if the values of the case expressions do not all have the same type.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=3528
+ */
+ public void test_switchExpression_case_differentTypes() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " var v = 1;",
+ " switch (v) {",
+ " case 0: break;",
" case 'a': break;",
- " case 12.3: break;",
" }",
"}",
"");
assertErrors(
libraryResult.getErrors(),
- errEx(TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE, 6, 10, 3),
- errEx(TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE, 7, 10, 4));
+ errEx(TypeErrorCode.CASE_EXPRESSIONS_SHOULD_BE_SAME_TYPE, 6, 10, 3));
}
/**

Powered by Google App Engine
This is Rietveld 408576698