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

Side by Side Diff: compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java

Issue 10831373: Issue 4543. Use complete Resolver before constants analyzer (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 package com.google.dart.compiler.resolver; 5 package com.google.dart.compiler.resolver;
6 6
7 import static com.google.dart.compiler.common.ErrorExpectation.errEx; 7 import static com.google.dart.compiler.common.ErrorExpectation.errEx;
8 8
9 import com.google.common.base.Joiner; 9 import com.google.common.base.Joiner;
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 "}", 74 "}",
75 "class A {", 75 "class A {",
76 " var f1 = new Val(1);", 76 " var f1 = new Val(1);",
77 " var f2 = this;", 77 " var f2 = this;",
78 " var f3 = new Val(f1);", 78 " var f3 = new Val(f1);",
79 "}", 79 "}",
80 "class B extends A {", 80 "class B extends A {",
81 " var f2 = new Val(f3);", 81 " var f2 = new Val(f3);",
82 "}", 82 "}",
83 ""), 83 ""),
84 errEx(ResolverErrorCode.CANNOT_USE_THIS_IN_INSTANCE_FIELD_INITIALIZER, 8 , 11, 4), 84 errEx(ResolverErrorCode.THIS_OUTSIDE_OF_METHOD, 8, 11, 4),
85 errEx(ResolverErrorCode.CANNOT_USE_INSTANCE_FIELD_IN_INSTANCE_FIELD_INIT IALIZER, 9, 19, 2), 85 errEx(ResolverErrorCode.CANNOT_USE_INSTANCE_FIELD_IN_INSTANCE_FIELD_INIT IALIZER, 9, 19, 2),
86 errEx(ResolverErrorCode.CANNOT_USE_INSTANCE_FIELD_IN_INSTANCE_FIELD_INIT IALIZER, 12, 19, 2)); 86 errEx(ResolverErrorCode.CANNOT_USE_INSTANCE_FIELD_IN_INSTANCE_FIELD_INIT IALIZER, 12, 19, 2));
87 } 87 }
88 88
89 /** 89 /**
90 * We can reference top-level fields, because they are static. 90 * We can reference top-level fields, because they are static.
91 * <p> 91 * <p>
92 * http://code.google.com/p/dart/issues/detail?id=4400 92 * http://code.google.com/p/dart/issues/detail?id=4400
93 */ 93 */
94 public void test_instanceVariable_nonConstInitializer_topLevelField() { 94 public void test_instanceVariable_nonConstInitializer_topLevelField() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 public void test_constConstructor_superInvocation() throws Exception { 145 public void test_constConstructor_superInvocation() throws Exception {
146 resolveAndTestCtConstExpectErrors( 146 resolveAndTestCtConstExpectErrors(
147 Joiner.on("\n").join( 147 Joiner.on("\n").join(
148 "// filler filler filler filler filler filler filler filler filler f iller", 148 "// filler filler filler filler filler filler filler filler filler f iller",
149 "class Object {}", 149 "class Object {}",
150 "class A {", 150 "class A {",
151 " final v;", 151 " final v;",
152 " const A(this.v);", 152 " const A(this.v);",
153 "}", 153 "}",
154 "class B extends A {", 154 "class B extends A {",
155 " const A() : super(generateValue());", 155 " const B() : super(generateValue());",
156 " static generateValue() => 42;", 156 " static generateValue() => 42;",
157 "}", 157 "}",
158 ""), 158 ""),
159 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 8, 21, 15)); 159 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 8, 21, 15));
160 } 160 }
161 161
162 /** 162 /**
163 * At compile time we "trust" user that parameter will have correct type. 163 * At compile time we "trust" user that parameter will have correct type.
164 */ 164 */
165 public void test_constConstructor_constInitializerValue_plusDynamic() { 165 public void test_constConstructor_constInitializerValue_plusDynamic() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 " c = 1 & null,", 203 " c = 1 & null,",
204 " d = ~null,", 204 " d = ~null,",
205 " e = -null;", 205 " e = -null;",
206 "}", 206 "}",
207 "")); 207 ""));
208 } 208 }
209 209
210 public void test_nonConstantExpressions() { 210 public void test_nonConstantExpressions() {
211 resolveAndTestCtConstExpectErrors( 211 resolveAndTestCtConstExpectErrors(
212 Joiner.on("\n").join( 212 Joiner.on("\n").join(
213 "class Object {}",
214 "var x = 0;", 213 "var x = 0;",
215 "const c1 = const {'$x' : 1};", 214 "const c1 = const {'$x' : 1};",
216 "const c2 = const {'key': []};", 215 "const c2 = const {'key': []};",
217 "const c3 = const [new Object()];"), 216 "const c3 = const [new Object()];",
218 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 3, 21, 1), 217 "class Object {}",
219 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 4, 26,2), 218 "class String {}",
220 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 5, 19, 12)); 219 ""),
220 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 2, 21, 1),
221 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 3, 26,2),
222 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 4, 19, 12));
221 } 223 }
222 224
223 public void test_expressionsWithNull() { 225 public void test_expressionsWithNull() {
224 resolveAndTestCtConst(Joiner.on("\n").join( 226 resolveAndTestCtConst(Joiner.on("\n").join(
225 "class Object {}", 227 "class Object {}",
226 "var b = null === '';")); 228 "var b = null === '';"));
227 } 229 }
228 230
229 public void test_parameterDefaultValue_inLocalFunction() { 231 public void test_parameterDefaultValue_inLocalFunction() {
230 resolveAndTestCtConstExpectErrors( 232 resolveAndTestCtConstExpectErrors(
231 Joiner.on("\n").join( 233 Joiner.on("\n").join(
232 "// filler filler filler filler filler filler filler filler filler f iller", 234 "// filler filler filler filler filler filler filler filler filler f iller",
233 "class Object {}",
234 "main() {", 235 "main() {",
235 " int x = 1;", 236 " int x = 1;",
236 " void func([var y = x]) {}", 237 " void func([var y = x]) {}",
237 "}", 238 "}",
239 "class Object {}",
240 "class int {}",
238 ""), 241 ""),
239 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 5, 21, 1)); 242 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 4, 21, 1));
240 } 243 }
241 244
242 public void test_stringInterpolation_referenceConstVar_num() { 245 public void test_stringInterpolation_referenceConstVar_num() {
243 resolveAndTestCtConstExpectErrors(Joiner.on("\n").join( 246 resolveAndTestCtConstExpectErrors(Joiner.on("\n").join(
244 "// filler filler filler filler filler filler filler filler filler fille r", 247 "// filler filler filler filler filler filler filler filler filler fille r",
245 "class Object {}", 248 "class Object {}",
246 "final a = 'aaa';", 249 "final a = 'aaa';",
247 "final v = '$a';", 250 "final v = '$a';",
248 "")); 251 ""));
249 } 252 }
(...skipping 14 matching lines...) Expand all
264 "final a = false;", 267 "final a = false;",
265 "final v = '$a';", 268 "final v = '$a';",
266 "")); 269 ""));
267 } 270 }
268 271
269 public void test_stringInterpolation_referenceConstVar_Object() { 272 public void test_stringInterpolation_referenceConstVar_Object() {
270 resolveAndTestCtConstExpectErrors( 273 resolveAndTestCtConstExpectErrors(
271 Joiner.on("\n").join( 274 Joiner.on("\n").join(
272 "// filler filler filler filler filler filler filler filler filler f iller", 275 "// filler filler filler filler filler filler filler filler filler f iller",
273 "class Object {}", 276 "class Object {}",
274 "final a = const Object();", 277 "class C {",
278 " const C();",
279 "}",
280 "final a = const C();",
275 "final v = '$a';", 281 "final v = '$a';",
276 ""), 282 ""),
277 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING_NUMBER_BOOL, 4, 13, 1)); 283 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING_NUMBER_BOOL, 7, 13, 1));
278 } 284 }
279 285
280 public void test_stringInterpolation_inMethod() { 286 public void test_stringInterpolation_inMethod() {
281 resolveAndTestCtConstExpectErrors(Joiner.on("\n").join( 287 resolveAndTestCtConstExpectErrors(Joiner.on("\n").join(
282 "// filler filler filler filler filler filler filler filler filler fille r", 288 "// filler filler filler filler filler filler filler filler filler fille r",
283 "class Object {}", 289 "class Object {}",
284 "class Conster {", 290 "class Conster {",
285 " const Conster(this.value);", 291 " const Conster(this.value);",
286 " final value;", 292 " final value;",
287 "}", 293 "}",
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 resolveAndTestCtConstExpectErrors( 391 resolveAndTestCtConstExpectErrors(
386 Joiner.on("\n").join( 392 Joiner.on("\n").join(
387 "// filler filler filler filler filler filler filler filler filler f iller", 393 "// filler filler filler filler filler filler filler filler filler f iller",
388 "class Object {}", 394 "class Object {}",
389 "class A {", 395 "class A {",
390 " m() {}", 396 " m() {}",
391 " static final V1 = m;", 397 " static final V1 = m;",
392 "}", 398 "}",
393 "final V2 = A.m;", 399 "final V2 = A.m;",
394 ""), 400 ""),
401 errEx(ResolverErrorCode.ILLEGAL_METHOD_ACCESS_FROM_STATIC, 5, 21, 1),
402 errEx(ResolverErrorCode.NOT_A_STATIC_METHOD, 7, 14, 1),
395 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 5, 21, 1), 403 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 5, 21, 1),
396 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 7, 12, 3)); 404 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 7, 12, 3));
397 } 405 }
398 406
399 public void testConstantBinaryExpression12() { 407 public void testConstantBinaryExpression12() {
400 // Multiple binary expressions 408 // Multiple binary expressions
401 resolveAndTestCtConst(Joiner.on("\n").join( 409 resolveAndTestCtConst(Joiner.on("\n").join(
402 "class Object {}", 410 "class Object {}",
403 "class A {", 411 "class A {",
404 " static final INT_LIT = 5;", 412 " static final INT_LIT = 5;",
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 " static final person = 'earthling';", 667 " static final person = 'earthling';",
660 " static final s = 'Hello ${foo()}!';", 668 " static final s = 'Hello ${foo()}!';",
661 "}"), 669 "}"),
662 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 670 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION,
663 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING_NUMBER_BOOL); 671 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_STRING_NUMBER_BOOL);
664 } 672 }
665 673
666 public void testConstantTypedLiteralAssign1() { 674 public void testConstantTypedLiteralAssign1() {
667 resolveAndTestCtConst(Joiner.on("\n").join( 675 resolveAndTestCtConst(Joiner.on("\n").join(
668 "class Object {}", 676 "class Object {}",
677 "class String {}",
669 "class List<T> {}", 678 "class List<T> {}",
670 "class Map<K,V> {}", 679 "class Map<K,V> {}",
671 "class A {", 680 "class A {",
672 " static final aList = const[1, 2, 3];", // array literal 681 " static final aList = const[1, 2, 3];", // array literal
673 " static final map = const { '1': 'one', '2': 'banana' };", // map lite ral 682 " static final map = const { '1': 'one', '2': 'banana' };", // map lite ral
674 " static final val = aList[2];", 683 " static final val = aList[2];",
675 "}")); 684 "}"));
676 } 685 }
677 686
678 public void testConstantTypedLiteralAssign2() { 687 public void testConstantTypedLiteralAssign2() {
(...skipping 15 matching lines...) Expand all
694 " static foo() { return 1; }", 703 " static foo() { return 1; }",
695 " // const array literal contains non-const member", 704 " // const array literal contains non-const member",
696 " static final aList = const [foo(), 2, 3];", 705 " static final aList = const [foo(), 2, 3];",
697 "}"), 706 "}"),
698 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); 707 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION);
699 } 708 }
700 709
701 public void testConstantTypedLiteralAssign4() { 710 public void testConstantTypedLiteralAssign4() {
702 resolveAndTestCtConst(Joiner.on("\n").join( 711 resolveAndTestCtConst(Joiner.on("\n").join(
703 "class Object {}", 712 "class Object {}",
713 "class String {}",
704 "class Map<K,V> {}", 714 "class Map<K,V> {}",
705 "class A {", 715 "class A {",
706 " // map literal is not const", 716 " // map literal is not const",
707 " static final aMap = { '1': 'one', '2': 'banana' };", 717 " static final aMap = { '1': 'one', '2': 'banana' };",
708 "}"), 718 "}"),
709 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); 719 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION);
710 } 720 }
711 public void testConstantTypedLiteralAssign5() { 721 public void testConstantTypedLiteralAssign5() {
712 resolveAndTestCtConst(Joiner.on("\n").join( 722 resolveAndTestCtConst(Joiner.on("\n").join(
713 "class Object {}", 723 "class Object {}",
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 "interface int {}", 965 "interface int {}",
956 "class A {", 966 "class A {",
957 " static final int value7 = ('Invalid') / 1;", 967 " static final int value7 = ('Invalid') / 1;",
958 " static final int value8 = value7 & 0xFFFF;", 968 " static final int value8 = value7 & 0xFFFF;",
959 "}"), 969 "}"),
960 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11), 970 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11),
961 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11), 971 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 4, 29, 11),
962 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 29, 6)) ; 972 errEx(ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_INT, 5, 29, 6)) ;
963 } 973 }
964 } 974 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698