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

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

Issue 10829365: Issue 4553. Any constant is valid for 'case'. (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/TypeAnalyzer.java ('k') | tests/co19/co19-compiler.status » ('j') | 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 6095fbf5e636233a1c524235490c43a3662962c4..281e7e50e288f4c60a77a05382de04a4e874d7d6 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -277,13 +277,18 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
/**
* It is a compile-time error if the values of the case expressions are not compile-time
- * constants, of type int or String.
+ * constants.
* <p>
- * http://code.google.com/p/dart/issues/detail?id=3528
+ * http://code.google.com/p/dart/issues/detail?id=4553
*/
- public void test_switchExpression_case_notIntString() throws Exception {
+ public void test_switchExpression_case_anyConst() throws Exception {
AnalyzeLibraryResult libraryResult = analyzeLibrary(
"// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " const A();",
+ "}",
+ "final A CONST_1 = const A();",
+ "final A CONST_2 = const A();",
"foo(var v) {",
" switch (v) {",
" case 0: break;",
@@ -294,11 +299,59 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
" switch (v) {",
" case 0.0: break;",
" }",
+ " switch (v) {",
+ " case CONST_1: break;",
+ " case CONST_2: break;",
+ " }",
+ "}",
+ "");
+ assertErrors(libraryResult.getErrors());
+ }
+
+ /**
+ * It is a compile-time error if the values of the case expressions are not compile-time
+ * constants.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=4553
+ */
+ public void test_switchExpression_case_notConst() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {}",
+ "foo(var v) {",
+ " A notConst = new A();",
+ " switch (v) {",
+ " case notConst: break;",
+ " }",
+ "}",
+ "");
+ assertErrors(
+ libraryResult.getErrors(),
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 6, 10, 8));
+ }
+
+ /**
+ * It is a compile-time error if the class C implements the operator ==.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=4553
+ */
+ public void test_switchExpression_case_hasOperatorEquals() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class C {",
+ " const C();",
+ " operator equals(other) => false;",
+ "}",
+ "const C CONST = const C();",
+ "foo(var v) {",
+ " switch (v) {",
+ " case CONST: break;",
+ " }",
"}",
"");
assertErrors(
libraryResult.getErrors(),
- errEx(TypeErrorCode.CASE_EXPRESSION_SHOULD_BE_INT_STRING, 10, 10, 3));
+ errEx(TypeErrorCode.CASE_EXPRESSION_TYPE_SHOULD_NOT_HAVE_EQUALS, 9, 10, 5));
}
/**
« no previous file with comments | « compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698