Index: compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java |
diff --git a/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java b/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java |
index 79e43e4cbfe6f38be96eb7d271ef37408c14e29a..8fa859518bd0a80135c2f3b16065535951874f7d 100644 |
--- a/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java |
+++ b/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java |
@@ -34,6 +34,72 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"}")); |
} |
+ public void test_parameterDefaultValue_inLocalFunction() { |
+ resolveAndTestCtConstExpectErrors( |
+ Joiner.on("\n").join( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "class Object {}", |
+ "main() {", |
+ " int x = 1;", |
+ " void func([var y = x]) {}", |
+ "}", |
+ ""), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 5, 21, 1)); |
+ } |
+ |
+ public void test_stringInterpolation_referenceConstVar_num() { |
+ resolveAndTestCtConstExpectErrors(Joiner.on("\n").join( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "class Object {}", |
+ "final a = 'aaa';", |
+ "final v = '$a';", |
+ "")); |
+ } |
+ |
+ public void test_stringInterpolation_referenceConstVar_String() { |
+ resolveAndTestCtConstExpectErrors(Joiner.on("\n").join( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "class Object {}", |
+ "final a = 1.0;", |
+ "final v = '$a';", |
+ "")); |
+ } |
+ |
+ public void test_stringInterpolation_referenceConstVar_bool() { |
+ resolveAndTestCtConstExpectErrors(Joiner.on("\n").join( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "class Object {}", |
+ "final a = false;", |
+ "final v = '$a';", |
+ "")); |
+ } |
+ |
+ public void test_stringInterpolation_referenceConstVar_Object() { |
+ resolveAndTestCtConstExpectErrors( |
+ Joiner.on("\n").join( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "class Object {}", |
+ "final a = const Object();", |
+ "final v = '$a';", |
+ ""), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING_NUMBER_BOOL, 4, 13, 1)); |
+ } |
+ |
+ public void test_stringInterpolation_inMethod() { |
+ resolveAndTestCtConstExpectErrors(Joiner.on("\n").join( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "class Object {}", |
+ "class Conster {", |
+ " const Conster(this.value);", |
+ " final value;", |
+ "}", |
+ "final a = 'aaa';", |
+ "f() {", |
+ " const Conster('$a');", |
+ "}", |
+ "")); |
+ } |
+ |
public void testConstantBinaryExpression1() { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
@@ -229,7 +295,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
" static final INT_LIT_REF = INT_LIT;", |
" static final DOUBLE_LIT = 1.5;", |
" static final BOOL_LIT = true;", |
- " static final STRING_LIT = \"Hello\";", |
+ " static final STRING_LIT = 'Hello';", |
" static final BOP4_0 = 5 % INT_LIT;", |
" static final BOP4_1 = INT_LIT % 5;", |
" static final BOP4_2 = 5.0 % DOUBLE_LIT;", |
@@ -243,8 +309,8 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
" static final BOP5_6 = 0x80 ^ 0x04;", |
" static final BOP6 = BOOL_LIT && true;", |
" static final BOP7 = false || BOOL_LIT;", |
- " static final BOP8 = STRING_LIT == \"World!\";", |
- " static final BOP9 = \"Hello\" != STRING_LIT;", |
+ " static final BOP8 = STRING_LIT == 'World!';", |
+ " static final BOP9 = 'Hello' != STRING_LIT;", |
" static final BOP10 = INT_LIT === INT_LIT_REF;", |
" static final BOP11 = BOOL_LIT !== true;", |
"}")); |
@@ -274,7 +340,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class String {}", |
"class A {", |
" static int foo() { return 1; }", |
- " static String bar() { return \"1\"; }", |
+ " static String bar() { return '1'; }", |
"}", |
"class B {", |
" static final BOP1 = 2 < A.foo();", |
@@ -342,7 +408,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
" const B();", |
" static final OBJECT_LIT = const B();", |
" static final INT_LIT = 1;", |
- " static final STRING_LIT = \"true\";", |
+ " static final STRING_LIT = 'true';", |
" static final BOP1 = STRING_LIT && true;", |
" static final BOP2 = false || STRING_LIT;", |
" static final BOP3 = 59 == OBJECT_LIT;", |
@@ -385,7 +451,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"class A {", |
" static final b = true;", |
- " static final s = \"apple\";", // string literal |
+ " static final s = 'apple';", // string literal |
" static final i = 1;", // integer literal |
" static final d = 3.3;", // double literal |
" static final h = 0xf;", // hex literal |
@@ -397,11 +463,12 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " foo() { return \"Eve\";}", |
- " static final person = \"earthling\";", |
- " static final s = \"Hello ${foo()}!\";", |
+ " foo() { return 'Eve';}", |
+ " static final person = 'earthling';", |
+ " static final s = 'Hello ${foo()}!';", |
"}"), |
- ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); |
+ ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, |
+ ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING_NUMBER_BOOL); |
} |
public void testConstantTypedLiteralAssign1() { |
@@ -411,7 +478,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Map<K,V> {}", |
"class A {", |
" static final aList = const[1, 2, 3];", // array literal |
- " static final map = const { \"1\": \"one\", \"2\": \"banana\" };", // map literal |
+ " static final map = const { '1': 'one', '2': 'banana' };", // map literal |
" static final val = aList[2];", |
"}")); |
} |
@@ -445,7 +512,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Map<K,V> {}", |
"class A {", |
" // map literal is not const", |
- " static final aMap = { \"1\": \"one\", \"2\": \"banana\" };", |
+ " static final aMap = { '1': 'one', '2': 'banana' };", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); |
} |
@@ -455,13 +522,12 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class String {}", |
"class Map<K,V> {}", |
"class A {", |
- " static String foo() { return \"one\"; }", |
- " static final String s = \"apple\";", |
+ " static String foo() { return 'one'; }", |
+ " static final String s = 'apple';", |
" // map literal contains non-const member", |
- " static final map = const { \"1\":foo(), \"2\": \"banana\" };", |
- " static final stringInterp = \"It was that woman who gave me the ${s}\";", |
+ " static final map = const { '1': foo(), '2': 'banana' };", |
+ " static final stringInterp = 'It was that woman who gave me the ${s}';", |
"}"), |
- ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); |
} |