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 d0b4bf1dab110257130116c89bf2f3f395b3fa51..8763508634144238176a5fd1380b514c2643e15e 100644 |
--- a/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java |
+++ b/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java |
@@ -4,10 +4,10 @@ |
package com.google.dart.compiler.resolver; |
-import static com.google.dart.compiler.common.ErrorExpectation.errEx; |
- |
import com.google.common.base.Joiner; |
+import static com.google.dart.compiler.common.ErrorExpectation.errEx; |
+ |
/** |
@@ -15,25 +15,6 @@ import com.google.common.base.Joiner; |
*/ |
public class CompileTimeConstantTest extends ResolverTestCase { |
- /** |
- * We should understand "const" keyword and temporary treat both "const" and "static final" as |
- * constants. |
- * <p> |
- * http://code.google.com/p/dart/issues/detail?id=3550 |
- */ |
- public void test_temporaryConstSyntax() { |
- resolveAndTestCtConst(Joiner.on("\n").join( |
- "class Object {}", |
- "const CT = 5;", |
- "class A {", |
- " const CF = 5;", |
- " const C1 = CT + 1;", |
- " const C2 = CF + 1;", |
- " static final SF1 = CT + 1;", |
- " static final SF2 = CF + 1;", |
- "}")); |
- } |
- |
public void test_nonConstArg() { |
resolveAndTestCtConstExpectErrors( |
Joiner.on("\n").join( |
@@ -242,21 +223,21 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 4, 21, 1)); |
} |
- public void test_stringInterpolation_referenceConstVar_num() { |
+ 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 = 'aaa';", |
- "final v = '$a';", |
+ "const a = 'aaa';", |
+ "const v = '$a';", |
"")); |
} |
- public void test_stringInterpolation_referenceConstVar_String() { |
+ 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 = 1.0;", |
- "final v = '$a';", |
+ "const a = 1.0;", |
+ "const v = '$a';", |
"")); |
} |
@@ -264,8 +245,8 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConstExpectErrors(Joiner.on("\n").join( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class Object {}", |
- "final a = false;", |
- "final v = '$a';", |
+ "const a = false;", |
+ "const v = '$a';", |
"")); |
} |
@@ -277,8 +258,8 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class C {", |
" const C();", |
"}", |
- "final a = const C();", |
- "final v = '$a';", |
+ "const a = const C();", |
+ "const v = '$a';", |
""), |
errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING_NUMBER_BOOL, 7, 13, 1)); |
} |
@@ -291,7 +272,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
" const Conster(this.value);", |
" final value;", |
"}", |
- "final a = 'aaa';", |
+ "const a = 'aaa';", |
"f() {", |
" const Conster('$a');", |
"}", |
@@ -302,15 +283,15 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final INT_LIT = 5;", |
- " static final BOP1_0 = INT_LIT + 1;", |
- " static final BOP1_1 = 1 + INT_LIT;", |
- " static final BOP1_2 = INT_LIT - 1;", |
- " static final BOP1_3 = 1 - INT_LIT;", |
- " static final BOP1_4 = INT_LIT * 1;", |
- " static final BOP1_5 = 1 * INT_LIT;", |
- " static final BOP1_6 = INT_LIT / 1;", |
- " static final BOP1_7 = 1 / INT_LIT;", |
+ " static const INT_LIT = 5;", |
+ " static const BOP1_0 = INT_LIT + 1;", |
+ " static const BOP1_1 = 1 + INT_LIT;", |
+ " static const BOP1_2 = INT_LIT - 1;", |
+ " static const BOP1_3 = 1 - INT_LIT;", |
+ " static const BOP1_4 = INT_LIT * 1;", |
+ " static const BOP1_5 = 1 * INT_LIT;", |
+ " static const BOP1_6 = INT_LIT / 1;", |
+ " static const BOP1_7 = 1 / INT_LIT;", |
"}")); |
} |
@@ -318,16 +299,16 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final INT_LIT = 5;", |
- " static final INT_LIT_REF = INT_LIT;", |
- " static final DOUBLE_LIT = 1.5;", |
- " static final BOOL_LIT = true;", |
+ " static const INT_LIT = 5;", |
+ " static const INT_LIT_REF = INT_LIT;", |
+ " static const DOUBLE_LIT = 1.5;", |
+ " static const BOOL_LIT = true;", |
" // Multiple binary expresions", |
- " static final BOP1 = 1 * INT_LIT / 3 + INT_LIT + 9;", |
+ " static const BOP1 = 1 * INT_LIT / 3 + INT_LIT + 9;", |
" // Parenthized expression", |
- " static final BOP2 = ( 1 > 2 );", |
- " static final BOP3 = (1 * 2) + 3;", |
- " static final BOP4 = 3 + (1 * 2);", |
+ " static const BOP2 = ( 1 > 2 );", |
+ " static const BOP3 = (1 * 2) + 3;", |
+ " static const BOP4 = 3 + (1 * 2);", |
"}")); |
} |
@@ -335,14 +316,14 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final INT_LIT = 5;", |
- " static final DOUBLE_LIT = 1.5;", |
+ " static const INT_LIT = 5;", |
+ " static const DOUBLE_LIT = 1.5;", |
" const A();", |
- " static final OBJECT_LIT = const A();", |
+ " static const OBJECT_LIT = const A();", |
" // Multiple binary expresions", |
- " static final BOP1_0 = 0 + 1 + OBJECT_LIT;", |
- " static final BOP1_1 = 0 + OBJECT_LIT + 1;", |
- " static final BOP1_2 = OBJECT_LIT + 3 + 9;", |
+ " static const BOP1_0 = 0 + 1 + OBJECT_LIT;", |
+ " static const BOP1_1 = 0 + OBJECT_LIT + 1;", |
+ " static const BOP1_2 = OBJECT_LIT + 3 + 9;", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, |
@@ -356,11 +337,11 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final a = b;", |
- " static final b = a;", |
+ " static const F1 = F2;", |
+ " static const F2 = F1;", |
"}"), |
- errEx(ResolverErrorCode.CIRCULAR_REFERENCE, 3, 20, 1), |
- errEx(ResolverErrorCode.CIRCULAR_REFERENCE, 4, 20, 1)); |
+ errEx(ResolverErrorCode.CIRCULAR_REFERENCE, 3, 21, 2), |
+ errEx(ResolverErrorCode.CIRCULAR_REFERENCE, 4, 21, 2)); |
} |
public void test_topLevelFunctionReference() { |
@@ -369,7 +350,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"m() {}", |
"class A {", |
- " static final V1 = m;", |
+ " static const V1 = m;", |
"}", |
"final V2 = m;", |
"")); |
@@ -381,7 +362,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"class A {", |
" static m() {}", |
- " static final V1 = m;", |
+ " static const V1 = m;", |
"}", |
"final V2 = A.m;", |
"")); |
@@ -394,7 +375,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"class A {", |
" m() {}", |
- " static final V1 = m;", |
+ " static const V1 = m;", |
"}", |
"final V2 = A.m;", |
""), |
@@ -409,16 +390,16 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final INT_LIT = 5;", |
- " static final DOUBLE_LIT = 1.5;", |
+ " static const INT_LIT = 5;", |
+ " static const DOUBLE_LIT = 1.5;", |
" const A();", |
- " static final OBJECT_LIT = new A();", |
- " static final PP0 = 0 - (1 + OBJECT_LIT);", |
- " static final PP1 = 0 + (OBJECT_LIT + 1);", |
- " static final PP2 = (OBJECT_LIT + 3) + 9;", |
- " static final PP3 = (OBJECT_LIT) + 3 + 9;", |
- " static final PP4 = (OBJECT_LIT + 3 + 9);", |
- " static final PP5 = OBJECT_LIT + (3 + 9);", |
+ " static const OBJECT_LIT = new A();", |
+ " static const PP0 = 0 - (1 + OBJECT_LIT);", |
+ " static const PP1 = 0 + (OBJECT_LIT + 1);", |
+ " static const PP2 = (OBJECT_LIT + 3) + 9;", |
+ " static const PP3 = (OBJECT_LIT) + 3 + 9;", |
+ " static const PP4 = (OBJECT_LIT + 3 + 9);", |
+ " static const PP5 = OBJECT_LIT + (3 + 9);", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, |
@@ -444,15 +425,15 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final DOUBLE_LIT = 1.5;", |
- " static final BOP2_0 = DOUBLE_LIT + 1.5;", |
- " static final BOP2_1 = 1.5 + DOUBLE_LIT;", |
- " static final BOP2_2 = DOUBLE_LIT - 1.5;", |
- " static final BOP2_3 = 1.5 - DOUBLE_LIT;", |
- " static final BOP2_4 = DOUBLE_LIT * 1.5;", |
- " static final BOP2_5 = 1.5 * DOUBLE_LIT;", |
- " static final BOP2_6 = DOUBLE_LIT / 1.5;", |
- " static final BOP2_7 = 1.5 / DOUBLE_LIT;", |
+ " static const DOUBLE_LIT = 1.5;", |
+ " static const BOP2_0 = DOUBLE_LIT + 1.5;", |
+ " static const BOP2_1 = 1.5 + DOUBLE_LIT;", |
+ " static const BOP2_2 = DOUBLE_LIT - 1.5;", |
+ " static const BOP2_3 = 1.5 - DOUBLE_LIT;", |
+ " static const BOP2_4 = DOUBLE_LIT * 1.5;", |
+ " static const BOP2_5 = 1.5 * DOUBLE_LIT;", |
+ " static const BOP2_6 = DOUBLE_LIT / 1.5;", |
+ " static const BOP2_7 = 1.5 / DOUBLE_LIT;", |
"}")); |
} |
@@ -460,30 +441,30 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final INT_LIT = 5;", |
- " static final BOP3_0 = 2 < INT_LIT;", |
- " static final BOP3_1 = INT_LIT < 2;", |
- " static final BOP3_2 = 2 > INT_LIT;", |
- " static final BOP3_3 = INT_LIT > 2;", |
+ " static const INT_LIT = 5;", |
+ " static const BOP3_0 = 2 < INT_LIT;", |
+ " static const BOP3_1 = INT_LIT < 2;", |
+ " static const BOP3_2 = 2 > INT_LIT;", |
+ " static const BOP3_3 = INT_LIT > 2;", |
"}")); |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final INT_LIT = 5;", |
- " static final DOUBLE_LIT = 1.5;", |
- " static final BOP3_4 = 2 < DOUBLE_LIT;", |
- " static final BOP3_5 = DOUBLE_LIT < 2;", |
- " static final BOP3_6 = 2 > DOUBLE_LIT;", |
- " static final BOP3_7 = DOUBLE_LIT > 2;", |
- " static final BOP3_8 = 2 <= INT_LIT;", |
- " static final BOP3_9 = INT_LIT <= 2;", |
- " static final BOP3_10 = 2 >= INT_LIT;", |
- " static final BOP3_11 = INT_LIT >= 2;", |
- " static final BOP3_12 = 2.0 <= DOUBLE_LIT;", |
- " static final BOP3_13 = DOUBLE_LIT <= 2.0;", |
- " static final BOP3_14 = 2.0 >= DOUBLE_LIT;", |
- " static final BOP3_15 = DOUBLE_LIT >= 2;", |
+ " static const INT_LIT = 5;", |
+ " static const DOUBLE_LIT = 1.5;", |
+ " static const BOP3_4 = 2 < DOUBLE_LIT;", |
+ " static const BOP3_5 = DOUBLE_LIT < 2;", |
+ " static const BOP3_6 = 2 > DOUBLE_LIT;", |
+ " static const BOP3_7 = DOUBLE_LIT > 2;", |
+ " static const BOP3_8 = 2 <= INT_LIT;", |
+ " static const BOP3_9 = INT_LIT <= 2;", |
+ " static const BOP3_10 = 2 >= INT_LIT;", |
+ " static const BOP3_11 = INT_LIT >= 2;", |
+ " static const BOP3_12 = 2.0 <= DOUBLE_LIT;", |
+ " static const BOP3_13 = DOUBLE_LIT <= 2.0;", |
+ " static const BOP3_14 = 2.0 >= DOUBLE_LIT;", |
+ " static const BOP3_15 = DOUBLE_LIT >= 2;", |
"}")); |
} |
@@ -491,28 +472,28 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final INT_LIT = 5;", |
- " 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 BOP4_0 = 5 % INT_LIT;", |
- " static final BOP4_1 = INT_LIT % 5;", |
- " static final BOP4_2 = 5.0 % DOUBLE_LIT;", |
- " static final BOP4_3 = DOUBLE_LIT % 5.0;", |
- " static final BOP5_0 = 0x80 & 0x04;", |
- " static final BOP5_1 = 0x80 | 0x04;", |
- " static final BOP5_2 = 0x80 << 0x04;", |
- " static final BOP5_3 = 0x80 >> 0x04;", |
- " static final BOP5_4 = 0x80 ~/ 0x04;", |
- " static final BOP5_5 = DOUBLE_LIT ~/ DOUBLE_LIT;", |
- " 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 BOP10 = INT_LIT === INT_LIT_REF;", |
- " static final BOP11 = BOOL_LIT !== true;", |
+ " static const INT_LIT = 5;", |
+ " static const INT_LIT_REF = INT_LIT;", |
+ " static const DOUBLE_LIT = 1.5;", |
+ " static const BOOL_LIT = true;", |
+ " static const STRING_LIT = 'Hello';", |
+ " static const BOP4_0 = 5 % INT_LIT;", |
+ " static const BOP4_1 = INT_LIT % 5;", |
+ " static const BOP4_2 = 5.0 % DOUBLE_LIT;", |
+ " static const BOP4_3 = DOUBLE_LIT % 5.0;", |
+ " static const BOP5_0 = 0x80 & 0x04;", |
+ " static const BOP5_1 = 0x80 | 0x04;", |
+ " static const BOP5_2 = 0x80 << 0x04;", |
+ " static const BOP5_3 = 0x80 >> 0x04;", |
+ " static const BOP5_4 = 0x80 ~/ 0x04;", |
+ " static const BOP5_5 = DOUBLE_LIT ~/ DOUBLE_LIT;", |
+ " static const BOP5_6 = 0x80 ^ 0x04;", |
+ " static const BOP6 = BOOL_LIT && true;", |
+ " static const BOP7 = false || BOOL_LIT;", |
+ " static const BOP8 = STRING_LIT == 'World!';", |
+ " static const BOP9 = 'Hello' != STRING_LIT;", |
+ " static const BOP10 = INT_LIT === INT_LIT_REF;", |
+ " static const BOP11 = BOOL_LIT !== true;", |
"}")); |
} |
@@ -524,8 +505,8 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
" static int foo() { return 1; }", |
"}", |
"class B {", |
- " static final BOP1 = A.foo() * 1;", |
- " static final BOP2 = 1 * A.foo();", |
+ " static const BOP1 = A.foo() * 1;", |
+ " static const BOP2 = 1 * A.foo();", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, |
@@ -543,10 +524,10 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
" static String bar() { return '1'; }", |
"}", |
"class B {", |
- " static final BOP1 = 2 < A.foo();", |
- " static final BOP2 = A.foo() < 2;", |
- " static final BOP3 = A.foo();", |
- " static final BOP4 = A.bar();", |
+ " static const BOP1 = 2 < A.foo();", |
+ " static const BOP2 = A.foo() < 2;", |
+ " static const BOP3 = A.foo();", |
+ " static const BOP4 = A.bar();", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, |
@@ -563,8 +544,8 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class double {}", |
"class num {}", |
"class A {", |
- " static final BOP1 = 0x80 & 2.0;", |
- " static final BOP2 = 2.0 & 0x80;", |
+ " static const BOP1 = 0x80 & 2.0;", |
+ " static const BOP2 = 2.0 & 0x80;", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT); |
@@ -581,10 +562,10 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
" static bool foo() { return true; }", |
"}", |
" class B {", |
- " static final BOP3 = 45 && true;", |
- " static final BOP4 = true || 45;", |
- " static final BOP5 = true && A.foo();", |
- " static final BOP6 = A.foo() && false;", |
+ " static const BOP3 = 45 && true;", |
+ " static const BOP4 = true || 45;", |
+ " static const BOP5 = true && A.foo();", |
+ " static const BOP6 = A.foo() && false;", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN, |
@@ -606,15 +587,15 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"}", |
"class B {", |
" const B();", |
- " static final OBJECT_LIT = const B();", |
- " static final INT_LIT = 1;", |
- " static final STRING_LIT = 'true';", |
- " static final BOP1 = STRING_LIT && true;", |
- " static final BOP2 = false || STRING_LIT;", |
- " static final BOP3 = 59 == OBJECT_LIT;", |
- " static final BOP4 = OBJECT_LIT != 59;", |
- " static final BOP5 = INT_LIT === OBJECT_LIT;", |
- " static final BOP6 = OBJECT_LIT !== true;", |
+ " static const OBJECT_LIT = const B();", |
+ " static const INT_LIT = 1;", |
+ " static const STRING_LIT = 'true';", |
+ " static const BOP1 = STRING_LIT && true;", |
+ " static const BOP2 = false || STRING_LIT;", |
+ " static const BOP3 = 59 == OBJECT_LIT;", |
+ " static const BOP4 = OBJECT_LIT != 59;", |
+ " static const BOP5 = INT_LIT === OBJECT_LIT;", |
+ " static const BOP6 = OBJECT_LIT !== true;", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN, |
@@ -631,7 +612,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
" const A();", |
"}", |
"class B {", |
- " static final a = const A();", // Constant constructor |
+ " const a = const A();", // Constant constructor |
"}")); |
} |
@@ -641,7 +622,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"class A {", |
" const A();", |
- " static final a = new A();", // Error: not a constant constructor |
+ " const a = new A();", // Error: not a constant constructor |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); |
} |
@@ -650,12 +631,12 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final b = true;", |
- " 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 |
- " static final n = null;", // null |
+ " const b = true;", |
+ " const s = 'apple';", // string literal |
+ " const i = 1;", // integer literal |
+ " const d = 3.3;", // double literal |
+ " const h = 0xf;", // hex literal |
+ " const n = null;", // null |
"}")); |
} |
@@ -664,8 +645,8 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"class A {", |
" foo() { return 'Eve';}", |
- " static final person = 'earthling';", |
- " static final s = 'Hello ${foo()}!';", |
+ " const person = 'earthling';", |
+ " const s = 'Hello ${foo()}!';", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING_NUMBER_BOOL); |
@@ -678,9 +659,9 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class List<T> {}", |
"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 val = aList[2];", |
+ " const aList = const[1, 2, 3];", // array literal |
+ " const map = const { '1': 'one', '2': 'banana' };", // map literal |
+ " const val = aList[2];", |
"}")); |
} |
@@ -690,7 +671,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class List<T> {}", |
"class A {", |
" // array literal not const", |
- " static final aList= [1, 2, 3];", |
+ " const aList= [1, 2, 3];", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); |
} |
@@ -702,7 +683,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class A {", |
" static foo() { return 1; }", |
" // const array literal contains non-const member", |
- " static final aList = const [foo(), 2, 3];", |
+ " const aList = const [foo(), 2, 3];", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); |
} |
@@ -714,7 +695,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Map<K,V> {}", |
"class A {", |
" // map literal is not const", |
- " static final aMap = { '1': 'one', '2': 'banana' };", |
+ " const aMap = { '1': 'one', '2': 'banana' };", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); |
} |
@@ -725,10 +706,10 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Map<K,V> {}", |
"class A {", |
" static String foo() { return 'one'; }", |
- " static final String s = 'apple';", |
+ " const 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}';", |
+ " const map = const { '1': foo(), '2': 'banana' };", |
+ " const stringInterp = 'It was that woman who gave me the ${s}';", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); |
} |
@@ -737,11 +718,11 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final BOOL_LIT = true;", |
- " static final UOP1_0 = !BOOL_LIT;", |
- " static final UOP1_1 = BOOL_LIT || !true;", |
- " static final UOP1_2 = !BOOL_LIT || true;", |
- " static final UOP1_3 = !(BOOL_LIT && true);", |
+ " static const BOOL_LIT = true;", |
+ " static const UOP1_0 = !BOOL_LIT;", |
+ " static const UOP1_1 = BOOL_LIT || !true;", |
+ " static const UOP1_2 = !BOOL_LIT || true;", |
+ " static const UOP1_3 = !(BOOL_LIT && true);", |
"}")); |
} |
@@ -749,13 +730,13 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final BOOL_LIT = true;", |
- " static final INT_LIT = 123;", |
- " static final DOUBLE_LIT = 12.3;", |
- " static final UOP2_0 = ~0xf0;", |
- " static final UOP2_1 = ~INT_LIT;", |
- " static final UOP2_2 = ~INT_LIT & 123;", |
- " static final UOP2_3 = ~(INT_LIT | 0xff);", |
+ " static const BOOL_LIT = true;", |
+ " static const INT_LIT = 123;", |
+ " static const DOUBLE_LIT = 12.3;", |
+ " static const UOP2_0 = ~0xf0;", |
+ " static const UOP2_1 = ~INT_LIT;", |
+ " static const UOP2_2 = ~INT_LIT & 123;", |
+ " static const UOP2_3 = ~(INT_LIT | 0xff);", |
"}")); |
} |
@@ -763,16 +744,16 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final INT_LIT = 123;", |
- " static final DOUBLE_LIT = 12.3;", |
- " static final UOP3_0 = -0xf0;", |
- " static final UOP3_1 = -INT_LIT;", |
- " static final UOP3_2 = -INT_LIT + 123;", |
- " static final UOP3_3 = -(INT_LIT * 0xff);", |
- " static final UOP3_4 = -0xf0;", |
- " static final UOP3_5 = -DOUBLE_LIT;", |
- " static final UOP3_6 = -DOUBLE_LIT + 123;", |
- " static final UOP3_7 = -(DOUBLE_LIT * 0xff);", |
+ " static const INT_LIT = 123;", |
+ " static const DOUBLE_LIT = 12.3;", |
+ " static const UOP3_0 = -0xf0;", |
+ " static const UOP3_1 = -INT_LIT;", |
+ " static const UOP3_2 = -INT_LIT + 123;", |
+ " static const UOP3_3 = -(INT_LIT * 0xff);", |
+ " static const UOP3_4 = -0xf0;", |
+ " static const UOP3_5 = -DOUBLE_LIT;", |
+ " static const UOP3_6 = -DOUBLE_LIT + 123;", |
+ " static const UOP3_7 = -(DOUBLE_LIT * 0xff);", |
"}")); |
} |
@@ -782,12 +763,12 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class int {}", |
"class A {", |
" // Unary expression", |
- " static final BOOL_LIT = true;", |
+ " static const BOOL_LIT = true;", |
" static int foo() { return 3; }", |
- " static final UOP1 = !5;", |
- " static final UOP2 = !foo();", |
- " static final UOP3 = !(5);", |
- " static final UOP4 = !(foo());", |
+ " static const UOP1 = !5;", |
+ " static const UOP2 = !foo();", |
+ " static const UOP3 = !(5);", |
+ " static const UOP4 = !(foo());", |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN, |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, |
@@ -801,12 +782,12 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final a = 1;", |
+ " static const F = 1;", |
"}", |
"class B {", |
- " static final i = 1;", |
- " static final j = i;", // variable that is a compile-time constant |
- " static final k = A.a;", // variable that is a compile-time constant |
+ " const i = 1;", |
+ " const j = i;", // variable that is a compile-time constant |
+ " const k = A.F;", // variable that is a compile-time constant |
"}")); |
} |
@@ -815,7 +796,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"class A {", |
" static foo() {return 1;}", |
- " static final i = foo();", // Error: not a constant integer |
+ " const i = foo();", // Error: not a constant integer |
"}"), |
ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); |
} |
@@ -825,18 +806,18 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
resolveAndTest(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final foo;", |
+ " const foo;", |
"}"), |
- ResolverErrorCode.STATIC_FINAL_REQUIRES_VALUE); |
+ ResolverErrorCode.CONST_REQUIRES_VALUE); |
} |
public void testForwardLookupExpressions() { |
resolveAndTestCtConst(Joiner.on("\n").join( |
"class Object {}", |
"class A {", |
- " static final value1 = value2 * 2;", |
- " static final value2 = value3 * 4;", |
- " static final value3 = 8;", |
+ " const value1 = value2 * 2;", |
+ " const value2 = value3 * 4;", |
+ " const value3 = 8;", |
"}")); |
} |
@@ -862,14 +843,14 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"interface int {}", |
"class A {", |
- " static final int value1 = (1 << 5) - 1;", |
- " static final int value2 = value1 & 0xFFFF;", |
- " static final int value3 = (1 << 5) + 1;", |
- " static final int value4 = value3 & 0xFFFF;", |
- " static final int value5 = (1 << 5) * 1;", |
- " static final int value6 = value5 & 0xFFFF;", |
- " static final int value7 = (1 << 5) / 1;", |
- " static final int value8 = value7 & 0xFFFF;", |
+ " const int value1 = (1 << 5) - 1;", |
+ " const int value2 = value1 & 0xFFFF;", |
+ " const int value3 = (1 << 5) + 1;", |
+ " const int value4 = value3 & 0xFFFF;", |
+ " const int value5 = (1 << 5) * 1;", |
+ " const int value6 = value5 & 0xFFFF;", |
+ " const int value7 = (1 << 5) / 1;", |
+ " const int value8 = value7 & 0xFFFF;", |
"}")); |
} |
@@ -883,19 +864,19 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"interface double {}", |
"class A {", |
- " static final double value1 = (1.0 * 5.0) - 1.0;", |
- " static final double value2 = value1 + 99.0;", |
- " static final double value3 = (1.0 * 5.0) + 1.0;", |
- " static final double value4 = value3 * 99.0;", |
- " static final double value5 = (1.0 * 5.0) * 1.0;", |
- " static final double value6 = value5 * 99.0;", |
- " static final double value7 = (1.0 * 5.0) / 1.0;", |
- " static final double value8 = value7 * 99.0;", |
+ " const double value1 = (1.0 * 5.0) - 1.0;", |
+ " const double value2 = value1 + 99.0;", |
+ " const double value3 = (1.0 * 5.0) + 1.0;", |
+ " const double value4 = value3 * 99.0;", |
+ " const double value5 = (1.0 * 5.0) * 1.0;", |
+ " const double value6 = value5 * 99.0;", |
+ " const double value7 = (1.0 * 5.0) / 1.0;", |
+ " const double value8 = value7 * 99.0;", |
"}")); |
} |
/** |
- * Mixing doubles and ints in aritmetic should result in a double value. |
+ * Mixing doubles and ints in arithmetic should result in a double value. |
* Not explicitly called out for in the spec yet, but this is the runtime behavior. |
*/ |
public void testParenthizedMathExpressions3() { |
@@ -904,14 +885,14 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"interface double {}", |
"class A {", |
- " static final double value1 = (1 * 5) - 1.0;", |
- " static final double value2 = value1 + 99.0;", |
- " static final double value3 = (1 * 5) + 1.0;", |
- " static final double value4 = value3 * 99.0;", |
- " static final double value5 = (1 * 5) * 1.0;", |
- " static final double value6 = value5 * 99.0;", |
- " static final double value7 = (1 * 5) / 1.0;", |
- " static final double value8 = value7 * 99.0;", |
+ " const double value1 = (1 * 5) - 1.0;", |
+ " const double value2 = value1 + 99.0;", |
+ " const double value3 = (1 * 5) + 1.0;", |
+ " const double value4 = value3 * 99.0;", |
+ " const double value5 = (1 * 5) * 1.0;", |
+ " const double value6 = value5 * 99.0;", |
+ " const double value7 = (1 * 5) / 1.0;", |
+ " const double value8 = value7 * 99.0;", |
"}")); |
} |
@@ -925,50 +906,50 @@ public class CompileTimeConstantTest extends ResolverTestCase { |
"class Object {}", |
"interface int {}", |
"class A {", |
- " static final int value1 = ('Invalid') - 1;", |
- " static final int value2 = value1 & 0xFFFF;", |
+ " const int value1 = ('Invalid') - 1;", |
+ " const int value2 = value1 & 0xFFFF;", |
"}"), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 22, 11), |
// Unfortunately, the CTConst analyzer reports the same error twice |
// because value1 is analyzed twice, once for original assignment, and a |
// second time when used in the RHS of the value2 definition. |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 29, 6)); |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 22, 11), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 22, 6)); |
resolveAndTestCtConstExpectErrors( |
Joiner.on("\n").join( |
"class Object {}", |
"interface int {}", |
"class A {", |
- " static final int value3 = ('Invalid') + 1;", |
- " static final int value4 = value3 & 0xFFFF;", |
+ " const int value3 = ('Invalid') + 1;", |
+ " const int value4 = value3 & 0xFFFF;", |
"}"), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING, 4, 43, 1), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING, 4, 43, 1), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 29, 6)); |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING, 4, 36, 1), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING, 4, 36, 1), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 22, 6)); |
resolveAndTestCtConstExpectErrors( |
Joiner.on("\n").join( |
"class Object {}", |
"interface int {}", |
"class A {", |
- " static final int value5 = ('Invalid') * 1;", |
- " static final int value6 = value5 & 0xFFFF;", |
+ " const int value5 = ('Invalid') * 1;", |
+ " const int value6 = value5 & 0xFFFF;", |
"}"), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 29, 6)); |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 22, 11), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 22, 11), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 22, 6)); |
resolveAndTestCtConstExpectErrors( |
Joiner.on("\n").join( |
"class Object {}", |
"interface int {}", |
"class A {", |
- " static final int value7 = ('Invalid') / 1;", |
- " static final int value8 = value7 & 0xFFFF;", |
+ " const int value7 = ('Invalid') / 1;", |
+ " const int value8 = value7 & 0xFFFF;", |
"}"), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11), |
- errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 29, 6)); |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 22, 11), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 22, 11), |
+ errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 22, 6)); |
} |
} |