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

Unified Diff: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java

Issue 267923004: Check const map literal keys and switch case exprs using type of constant. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java
diff --git a/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java
index 2f1f71706f6222561701baabc2d47fa2a77a705a..5154738c5dd16af1502cb9ec4a471fe181bb1ade 100644
--- a/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java
+++ b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java
@@ -335,6 +335,31 @@ public class CompileTimeErrorCodeTest extends ResolverTestCase {
verify(source);
}
+ public void test_consistentCaseExpressionTypes_dynamic() throws Exception {
+ // Even though A.S and S have a static type of "dynamic", we should see
+ // that they match 'abc', because they are constant strings.
+ Source source = addSource(createSource(//
+ "class A {",
+ " static const S = 'A.S';",
+ "}",
+ "",
+ "const S = 'S';",
+ "",
+ "foo(var p) {",
+ " switch (p) {",
+ " case S:",
+ " break;",
+ " case A.S:",
+ " break;",
+ " case 'abc':",
+ " break;",
+ " }",
+ "}"));
+ resolve(source);
+ assertNoErrors(source);
+ verify(source);
+ }
+
public void test_constConstructorWithNonConstSuper_explicit() throws Exception {
Source source = addSource(createSource(//
"class A {",
@@ -655,6 +680,26 @@ public class CompileTimeErrorCodeTest extends ResolverTestCase {
verify(source);
}
+ public void test_constMapKeyTypeImplementsEquals_dynamic() throws Exception {
+ // Note: static type of B.a is "dynamic", but actual type of the const
+ // object is A. We need to make sure we examine the actual type when
+ // deciding whether there is a problem with operator==.
+ Source source = addSource(createSource(//
+ "class A {",
+ " const A();",
+ " operator ==(other) => false;",
+ "}",
+ "class B {",
+ " static const a = const A();",
+ "}",
+ "main() {",
+ " const {B.a : 0};",
+ "}"));
+ resolve(source);
+ assertErrors(source, CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS);
+ verify(source);
+ }
+
public void test_constMapKeyTypeImplementsEquals_super() throws Exception {
Source source = addSource(createSource(//
"class A {",
@@ -1855,6 +1900,34 @@ public class CompileTimeErrorCodeTest extends ResolverTestCase {
verify(source);
}
+ public void test_inconsistentCaseExpressionTypes_dynamic() throws Exception {
+ // Even though A.S and S have a static type of "dynamic", we should see
+ // that they fail to match 3, because they are constant strings.
+ Source source = addSource(createSource(//
+ "class A {",
+ " static const S = 'A.S';",
+ "}",
+ "",
+ "const S = 'S';",
+ "",
+ "foo(var p) {",
+ " switch (p) {",
+ " case 3:",
+ " break;",
+ " case S:",
+ " break;",
+ " case A.S:",
+ " break;",
+ " }",
+ "}"));
+ resolve(source);
+ assertErrors(
+ source,
+ CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES,
+ CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES);
+ verify(source);
+ }
+
public void test_inconsistentCaseExpressionTypes_repeated() throws Exception {
Source source = addSource(createSource(//
"f(var p) {",

Powered by Google App Engine
This is Rietveld 408576698