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

Side by Side Diff: pkg/analyzer/test/generated/compile_time_error_code_test.dart

Issue 682553002: Convert most of the EngineTestCase.createSource invocations into multi-line String literals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library engine.compile_time_error_code_test; 5 library engine.compile_time_error_code_test;
6 6
7 import 'package:analyzer/src/generated/source_io.dart'; 7 import 'package:analyzer/src/generated/source_io.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; 9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:unittest/unittest.dart' as _ut; 11 import 'package:unittest/unittest.dart' as _ut;
12 import 'resolver_test.dart'; 12 import 'resolver_test.dart';
13 import 'test_support.dart';
14 import '../reflective_tests.dart'; 13 import '../reflective_tests.dart';
15 14
16 15
17 class CompileTimeErrorCodeTest extends ResolverTestCase { 16 class CompileTimeErrorCodeTest extends ResolverTestCase {
18 void fail_compileTimeConstantRaisesException() { 17 void fail_compileTimeConstantRaisesException() {
19 Source source = addSource(EngineTestCase.createSource([])); 18 Source source = addSource(r'''
19 ''');
20 resolve(source); 20 resolve(source);
21 assertErrors(source, [CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAISES_EXCE PTION]); 21 assertErrors(source, [CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAISES_EXCE PTION]);
22 verify([source]); 22 verify([source]);
23 } 23 }
24 24
25 void fail_constEvalThrowsException() { 25 void fail_constEvalThrowsException() {
26 Source source = addSource(EngineTestCase.createSource([ 26 Source source = addSource(r'''
27 "class C {", 27 class C {
28 " const C();", 28 const C();
29 "}", 29 }
30 "f() { return const C(); }"])); 30 f() { return const C(); }''');
31 resolve(source); 31 resolve(source);
32 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTIO N]); 32 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTIO N]);
33 verify([source]); 33 verify([source]);
34 } 34 }
35 35
36 void fail_invalidIdentifierInAsync_async() { 36 void fail_invalidIdentifierInAsync_async() {
37 // TODO(brianwilkerson) Report this error. 37 // TODO(brianwilkerson) Report this error.
38 resetWithAsync(); 38 resetWithAsync();
39 Source source = addSource(EngineTestCase.createSource([ 39 Source source = addSource(r'''
40 "class A {", 40 class A {
41 " m() async {", 41 m() async {
42 " int async;", 42 int async;
43 " }", 43 }
44 "}"])); 44 }''');
45 resolve(source); 45 resolve(source);
46 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); 46 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]);
47 verify([source]); 47 verify([source]);
48 } 48 }
49 49
50 void fail_invalidIdentifierInAsync_await() { 50 void fail_invalidIdentifierInAsync_await() {
51 // TODO(brianwilkerson) Report this error. 51 // TODO(brianwilkerson) Report this error.
52 resetWithAsync(); 52 resetWithAsync();
53 Source source = addSource(EngineTestCase.createSource([ 53 Source source = addSource(r'''
54 "class A {", 54 class A {
55 " m() async {", 55 m() async {
56 " int await;", 56 int await;
57 " }", 57 }
58 "}"])); 58 }''');
59 resolve(source); 59 resolve(source);
60 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); 60 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]);
61 verify([source]); 61 verify([source]);
62 } 62 }
63 63
64 void fail_invalidIdentifierInAsync_yield() { 64 void fail_invalidIdentifierInAsync_yield() {
65 // TODO(brianwilkerson) Report this error. 65 // TODO(brianwilkerson) Report this error.
66 resetWithAsync(); 66 resetWithAsync();
67 Source source = addSource(EngineTestCase.createSource([ 67 Source source = addSource(r'''
68 "class A {", 68 class A {
69 " m() async {", 69 m() async {
70 " int yield;", 70 int yield;
71 " }", 71 }
72 "}"])); 72 }''');
73 resolve(source); 73 resolve(source);
74 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); 74 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]);
75 verify([source]); 75 verify([source]);
76 } 76 }
77 77
78 void fail_mixinDeclaresConstructor() { 78 void fail_mixinDeclaresConstructor() {
79 Source source = addSource(EngineTestCase.createSource([ 79 Source source = addSource(r'''
80 "class A {", 80 class A {
81 " A() {}", 81 A() {}
82 "}", 82 }
83 "class B extends Object mixin A {}"])); 83 class B extends Object mixin A {}''');
84 resolve(source); 84 resolve(source);
85 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); 85 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
86 verify([source]); 86 verify([source]);
87 } 87 }
88 88
89 void fail_mixinOfNonClass() { 89 void fail_mixinOfNonClass() {
90 // TODO(brianwilkerson) Compare with MIXIN_WITH_NON_CLASS_SUPERCLASS. 90 // TODO(brianwilkerson) Compare with MIXIN_WITH_NON_CLASS_SUPERCLASS.
91 Source source = addSource(EngineTestCase.createSource(["var A;", "class B ex tends Object mixin A {}"])); 91 Source source = addSource(r'''
92 var A;
93 class B extends Object mixin A {}''');
92 resolve(source); 94 resolve(source);
93 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); 95 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]);
94 verify([source]); 96 verify([source]);
95 } 97 }
96 98
97 void fail_objectCannotExtendAnotherClass() { 99 void fail_objectCannotExtendAnotherClass() {
98 Source source = addSource(EngineTestCase.createSource([])); 100 Source source = addSource(r'''
101 ''');
99 resolve(source); 102 resolve(source);
100 assertErrors(source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLAS S]); 103 assertErrors(source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLAS S]);
101 verify([source]); 104 verify([source]);
102 } 105 }
103 106
104 void fail_recursiveCompileTimeConstant() { 107 void fail_recursiveCompileTimeConstant() {
105 Source source = addSource(EngineTestCase.createSource([ 108 Source source = addSource(r'''
106 "class A {", 109 class A {
107 " const A();", 110 const A();
108 " final m = const A();", 111 final m = const A();
109 "}"])); 112 }''');
110 resolve(source); 113 resolve(source);
111 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]) ; 114 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]) ;
112 verify([source]); 115 verify([source]);
113 } 116 }
114 117
115 void fail_recursiveCompileTimeConstant_cycle() { 118 void fail_recursiveCompileTimeConstant_cycle() {
116 Source source = addSource(EngineTestCase.createSource(["const x = y + 1;", " const y = x + 1;"])); 119 Source source = addSource(r'''
120 const x = y + 1;
121 const y = x + 1;''');
117 resolve(source); 122 resolve(source);
118 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]) ; 123 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]) ;
119 verify([source]); 124 verify([source]);
120 } 125 }
121 126
122 void fail_superInitializerInObject() { 127 void fail_superInitializerInObject() {
123 Source source = addSource(EngineTestCase.createSource([])); 128 Source source = addSource(r'''
129 ''');
124 resolve(source); 130 resolve(source);
125 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]); 131 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]);
126 verify([source]); 132 verify([source]);
127 } 133 }
128 134
129 void fail_yieldEachInNonGenerator_async() { 135 void fail_yieldEachInNonGenerator_async() {
130 // TODO(brianwilkerson) We are currently parsing the yield statement as a bi nary expression. 136 // TODO(brianwilkerson) We are currently parsing the yield statement as a bi nary expression.
131 resetWithAsync(); 137 resetWithAsync();
132 Source source = addSource(EngineTestCase.createSource(["f() async {", " yie ld* 0;", "}"])); 138 Source source = addSource(r'''
139 f() async {
140 yield* 0;
141 }''');
133 resolve(source); 142 resolve(source);
134 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); 143 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]);
135 verify([source]); 144 verify([source]);
136 } 145 }
137 146
138 void fail_yieldEachInNonGenerator_sync() { 147 void fail_yieldEachInNonGenerator_sync() {
139 // TODO(brianwilkerson) We are currently parsing the yield statement as a bi nary expression. 148 // TODO(brianwilkerson) We are currently parsing the yield statement as a bi nary expression.
140 resetWithAsync(); 149 resetWithAsync();
141 Source source = addSource(EngineTestCase.createSource(["f() {", " yield* 0; ", "}"])); 150 Source source = addSource(r'''
151 f() {
152 yield* 0;
153 }''');
142 resolve(source); 154 resolve(source);
143 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); 155 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]);
144 verify([source]); 156 verify([source]);
145 } 157 }
146 158
147 void fail_yieldInNonGenerator_async() { 159 void fail_yieldInNonGenerator_async() {
148 // TODO(brianwilkerson) We are currently trying to parse the yield statement as a binary expression. 160 // TODO(brianwilkerson) We are currently trying to parse the yield statement as a binary expression.
149 resetWithAsync(); 161 resetWithAsync();
150 Source source = addSource(EngineTestCase.createSource(["f() async {", " yie ld 0;", "}"])); 162 Source source = addSource(r'''
163 f() async {
164 yield 0;
165 }''');
151 resolve(source); 166 resolve(source);
152 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); 167 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]);
153 verify([source]); 168 verify([source]);
154 } 169 }
155 170
156 void fail_yieldInNonGenerator_sync() { 171 void fail_yieldInNonGenerator_sync() {
157 // TODO(brianwilkerson) We are currently trying to parse the yield statement as a binary expression. 172 // TODO(brianwilkerson) We are currently trying to parse the yield statement as a binary expression.
158 resetWithAsync(); 173 resetWithAsync();
159 Source source = addSource(EngineTestCase.createSource(["f() {", " yield 0;" , "}"])); 174 Source source = addSource(r'''
175 f() {
176 yield 0;
177 }''');
160 resolve(source); 178 resolve(source);
161 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); 179 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]);
162 verify([source]); 180 verify([source]);
163 } 181 }
164 182
165 void test_accessPrivateEnumField() { 183 void test_accessPrivateEnumField() {
166 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); 184 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
167 analysisOptions.enableEnum = true; 185 analysisOptions.enableEnum = true;
168 resetWithOptions(analysisOptions); 186 resetWithOptions(analysisOptions);
169 Source source = addSource(EngineTestCase.createSource([ 187 Source source = addSource(r'''
170 "enum E { ONE }", 188 enum E { ONE }
171 "String name(E e) {", 189 String name(E e) {
172 " return e._name;", 190 return e._name;
173 "}"])); 191 }''');
174 resolve(source); 192 resolve(source);
175 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]); 193 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]);
176 // Cannot verify because "_name" cannot be resolved. 194 // Cannot verify because "_name" cannot be resolved.
177 } 195 }
178 196
179 void test_ambiguousExport() { 197 void test_ambiguousExport() {
180 Source source = addSource(EngineTestCase.createSource([ 198 Source source = addSource(r'''
181 "library L;", 199 library L;
182 "export 'lib1.dart';", 200 export 'lib1.dart';
183 "export 'lib2.dart';"])); 201 export 'lib2.dart';''');
184 addNamedSource("/lib1.dart", EngineTestCase.createSource(["library lib1;", " class N {}"])); 202 addNamedSource("/lib1.dart", r'''
185 addNamedSource("/lib2.dart", EngineTestCase.createSource(["library lib2;", " class N {}"])); 203 library lib1;
204 class N {}''');
205 addNamedSource("/lib2.dart", r'''
206 library lib2;
207 class N {}''');
186 resolve(source); 208 resolve(source);
187 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); 209 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]);
188 verify([source]); 210 verify([source]);
189 } 211 }
190 212
191 void test_asyncForInWrongContext() { 213 void test_asyncForInWrongContext() {
192 Source source = addSource(EngineTestCase.createSource(["f(list) {", " await for (var e in list) {", " }", "}"])); 214 Source source = addSource(r'''
215 f(list) {
216 await for (var e in list) {
217 }
218 }''');
193 resolve(source); 219 resolve(source);
194 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]); 220 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]);
195 verify([source]); 221 verify([source]);
196 } 222 }
197 223
198 void test_awaitInWrongContext_sync() { 224 void test_awaitInWrongContext_sync() {
199 resetWithAsync(); 225 resetWithAsync();
200 Source source = addSource(EngineTestCase.createSource(["f(x) {", " return a wait x;", "}"])); 226 Source source = addSource(r'''
227 f(x) {
228 return await x;
229 }''');
201 resolve(source); 230 resolve(source);
202 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); 231 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]);
203 verify([source]); 232 verify([source]);
204 } 233 }
205 234
206 void test_awaitInWrongContext_syncStar() { 235 void test_awaitInWrongContext_syncStar() {
207 resetWithAsync(); 236 resetWithAsync();
208 Source source = addSource(EngineTestCase.createSource(["f(x) sync* {", " yi eld await x;", "}"])); 237 Source source = addSource(r'''
238 f(x) sync* {
239 yield await x;
240 }''');
209 resolve(source); 241 resolve(source);
210 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); 242 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]);
211 verify([source]); 243 verify([source]);
212 } 244 }
213 245
214 void test_builtInIdentifierAsMixinName_classTypeAlias() { 246 void test_builtInIdentifierAsMixinName_classTypeAlias() {
215 Source source = addSource(EngineTestCase.createSource(["class A {}", "class B {}", "class as = A with B;"])); 247 Source source = addSource(r'''
248 class A {}
249 class B {}
250 class as = A with B;''');
216 resolve(source); 251 resolve(source);
217 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NA ME]); 252 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NA ME]);
218 verify([source]); 253 verify([source]);
219 } 254 }
220 255
221 void test_builtInIdentifierAsType_formalParameter_field() { 256 void test_builtInIdentifierAsType_formalParameter_field() {
222 Source source = addSource(EngineTestCase.createSource(["class A {", " var x ;", " A(static this.x);", "}"])); 257 Source source = addSource(r'''
258 class A {
259 var x;
260 A(static this.x);
261 }''');
223 resolve(source); 262 resolve(source);
224 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); 263 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]);
225 verify([source]); 264 verify([source]);
226 } 265 }
227 266
228 void test_builtInIdentifierAsType_formalParameter_simple() { 267 void test_builtInIdentifierAsType_formalParameter_simple() {
229 Source source = addSource(EngineTestCase.createSource(["f(static x) {", "}"] )); 268 Source source = addSource(r'''
269 f(static x) {
270 }''');
230 resolve(source); 271 resolve(source);
231 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); 272 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]);
232 verify([source]); 273 verify([source]);
233 } 274 }
234 275
235 void test_builtInIdentifierAsType_variableDeclaration() { 276 void test_builtInIdentifierAsType_variableDeclaration() {
236 Source source = addSource(EngineTestCase.createSource(["f() {", " typedef x ;", "}"])); 277 Source source = addSource(r'''
278 f() {
279 typedef x;
280 }''');
237 resolve(source); 281 resolve(source);
238 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); 282 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]);
239 verify([source]); 283 verify([source]);
240 } 284 }
241 285
242 void test_builtInIdentifierAsTypedefName_functionTypeAlias() { 286 void test_builtInIdentifierAsTypedefName_functionTypeAlias() {
243 Source source = addSource(EngineTestCase.createSource(["typedef bool as();"] )); 287 Source source = addSource("typedef bool as();");
244 resolve(source); 288 resolve(source);
245 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NA ME]); 289 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NA ME]);
246 verify([source]); 290 verify([source]);
247 } 291 }
248 292
249 void test_builtInIdentifierAsTypeName() { 293 void test_builtInIdentifierAsTypeName() {
250 Source source = addSource(EngineTestCase.createSource(["class as {}"])); 294 Source source = addSource("class as {}");
251 resolve(source); 295 resolve(source);
252 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME] ); 296 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME] );
253 verify([source]); 297 verify([source]);
254 } 298 }
255 299
256 void test_builtInIdentifierAsTypeParameterName() { 300 void test_builtInIdentifierAsTypeParameterName() {
257 Source source = addSource(EngineTestCase.createSource(["class A<as> {}"])); 301 Source source = addSource("class A<as> {}");
258 resolve(source); 302 resolve(source);
259 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAM ETER_NAME]); 303 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAM ETER_NAME]);
260 verify([source]); 304 verify([source]);
261 } 305 }
262 306
263 void test_caseExpressionTypeImplementsEquals() { 307 void test_caseExpressionTypeImplementsEquals() {
264 Source source = addSource(EngineTestCase.createSource([ 308 Source source = addSource(r'''
265 "class IntWrapper {", 309 class IntWrapper {
266 " final int value;", 310 final int value;
267 " const IntWrapper(this.value);", 311 const IntWrapper(this.value);
268 " bool operator ==(IntWrapper x) {", 312 bool operator ==(IntWrapper x) {
269 " return value == x.value;", 313 return value == x.value;
270 " }", 314 }
271 " get hashCode => value;", 315 get hashCode => value;
272 "}", 316 }
273 "", 317
274 "f(var a) {", 318 f(var a) {
275 " switch(a) {", 319 switch(a) {
276 " case(const IntWrapper(1)) : return 1;", 320 case(const IntWrapper(1)) : return 1;
277 " default: return 0;", 321 default: return 0;
278 " }", 322 }
279 "}"])); 323 }''');
280 resolve(source); 324 resolve(source);
281 assertErrors(source, [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_E QUALS]); 325 assertErrors(source, [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_E QUALS]);
282 verify([source]); 326 verify([source]);
283 } 327 }
284 328
285 void test_conflictingConstructorNameAndMember_field() { 329 void test_conflictingConstructorNameAndMember_field() {
286 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " A.x() {}", "}"])); 330 Source source = addSource(r'''
331 class A {
332 int x;
333 A.x() {}
334 }''');
287 resolve(source); 335 resolve(source);
288 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_ FIELD]); 336 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_ FIELD]);
289 verify([source]); 337 verify([source]);
290 } 338 }
291 339
292 void test_conflictingConstructorNameAndMember_method() { 340 void test_conflictingConstructorNameAndMember_method() {
293 Source source = addSource(EngineTestCase.createSource(["class A {", " const A.x();", " void x() {}", "}"])); 341 Source source = addSource(r'''
342 class A {
343 const A.x();
344 void x() {}
345 }''');
294 resolve(source); 346 resolve(source);
295 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_ METHOD]); 347 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_ METHOD]);
296 verify([source]); 348 verify([source]);
297 } 349 }
298 350
299 void test_conflictingGetterAndMethod_field_method() { 351 void test_conflictingGetterAndMethod_field_method() {
300 Source source = addSource(EngineTestCase.createSource([ 352 Source source = addSource(r'''
301 "class A {", 353 class A {
302 " final int m = 0;", 354 final int m = 0;
303 "}", 355 }
304 "class B extends A {", 356 class B extends A {
305 " m() {}", 357 m() {}
306 "}"])); 358 }''');
307 resolve(source); 359 resolve(source);
308 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); 360 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]);
309 verify([source]); 361 verify([source]);
310 } 362 }
311 363
312 void test_conflictingGetterAndMethod_getter_method() { 364 void test_conflictingGetterAndMethod_getter_method() {
313 Source source = addSource(EngineTestCase.createSource([ 365 Source source = addSource(r'''
314 "class A {", 366 class A {
315 " get m => 0;", 367 get m => 0;
316 "}", 368 }
317 "class B extends A {", 369 class B extends A {
318 " m() {}", 370 m() {}
319 "}"])); 371 }''');
320 resolve(source); 372 resolve(source);
321 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); 373 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]);
322 verify([source]); 374 verify([source]);
323 } 375 }
324 376
325 void test_conflictingGetterAndMethod_method_field() { 377 void test_conflictingGetterAndMethod_method_field() {
326 Source source = addSource(EngineTestCase.createSource([ 378 Source source = addSource(r'''
327 "class A {", 379 class A {
328 " m() {}", 380 m() {}
329 "}", 381 }
330 "class B extends A {", 382 class B extends A {
331 " int m;", 383 int m;
332 "}"])); 384 }''');
333 resolve(source); 385 resolve(source);
334 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); 386 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]);
335 verify([source]); 387 verify([source]);
336 } 388 }
337 389
338 void test_conflictingGetterAndMethod_method_getter() { 390 void test_conflictingGetterAndMethod_method_getter() {
339 Source source = addSource(EngineTestCase.createSource([ 391 Source source = addSource(r'''
340 "class A {", 392 class A {
341 " m() {}", 393 m() {}
342 "}", 394 }
343 "class B extends A {", 395 class B extends A {
344 " get m => 0;", 396 get m => 0;
345 "}"])); 397 }''');
346 resolve(source); 398 resolve(source);
347 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); 399 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]);
348 verify([source]); 400 verify([source]);
349 } 401 }
350 402
351 void test_conflictingTypeVariableAndClass() { 403 void test_conflictingTypeVariableAndClass() {
352 Source source = addSource(EngineTestCase.createSource(["class T<T> {", "}"]) ); 404 Source source = addSource(r'''
405 class T<T> {
406 }''');
353 resolve(source); 407 resolve(source);
354 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLA SS]); 408 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLA SS]);
355 verify([source]); 409 verify([source]);
356 } 410 }
357 411
358 void test_conflictingTypeVariableAndMember_field() { 412 void test_conflictingTypeVariableAndMember_field() {
359 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " va r T;", "}"])); 413 Source source = addSource(r'''
414 class A<T> {
415 var T;
416 }''');
360 resolve(source); 417 resolve(source);
361 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]); 418 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]);
362 verify([source]); 419 verify([source]);
363 } 420 }
364 421
365 void test_conflictingTypeVariableAndMember_getter() { 422 void test_conflictingTypeVariableAndMember_getter() {
366 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " ge t T => null;", "}"])); 423 Source source = addSource(r'''
424 class A<T> {
425 get T => null;
426 }''');
367 resolve(source); 427 resolve(source);
368 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]); 428 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]);
369 verify([source]); 429 verify([source]);
370 } 430 }
371 431
372 void test_conflictingTypeVariableAndMember_method() { 432 void test_conflictingTypeVariableAndMember_method() {
373 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " T( ) {}", "}"])); 433 Source source = addSource(r'''
434 class A<T> {
435 T() {}
436 }''');
374 resolve(source); 437 resolve(source);
375 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]); 438 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]);
376 verify([source]); 439 verify([source]);
377 } 440 }
378 441
379 void test_conflictingTypeVariableAndMember_method_static() { 442 void test_conflictingTypeVariableAndMember_method_static() {
380 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " st atic T() {}", "}"])); 443 Source source = addSource(r'''
444 class A<T> {
445 static T() {}
446 }''');
381 resolve(source); 447 resolve(source);
382 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]); 448 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]);
383 verify([source]); 449 verify([source]);
384 } 450 }
385 451
386 void test_conflictingTypeVariableAndMember_setter() { 452 void test_conflictingTypeVariableAndMember_setter() {
387 Source source = addSource(EngineTestCase.createSource(["class A<T> {", " se t T(x) {}", "}"])); 453 Source source = addSource(r'''
388 resolve(source); 454 class A<T> {
389 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]); 455 set T(x) {}
390 verify([source]); 456 }''');
457 resolve(source);
458 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEM BER]);
459 verify([source]);
391 } 460 }
392 461
393 void test_consistentCaseExpressionTypes_dynamic() { 462 void test_consistentCaseExpressionTypes_dynamic() {
394 // Even though A.S and S have a static type of "dynamic", we should see 463 // Even though A.S and S have a static type of "dynamic", we should see
395 // that they match 'abc', because they are constant strings. 464 // that they match 'abc', because they are constant strings.
396 Source source = addSource(EngineTestCase.createSource([ 465 Source source = addSource(r'''
397 "class A {", 466 class A {
398 " static const S = 'A.S';", 467 static const S = 'A.S';
399 "}", 468 }
400 "", 469
401 "const S = 'S';", 470 const S = 'S';
402 "", 471
403 "foo(var p) {", 472 foo(var p) {
404 " switch (p) {", 473 switch (p) {
405 " case S:", 474 case S:
406 " break;", 475 break;
407 " case A.S:", 476 case A.S:
408 " break;", 477 break;
409 " case 'abc':", 478 case 'abc':
410 " break;", 479 break;
411 " }", 480 }
412 "}"])); 481 }''');
413 resolve(source); 482 resolve(source);
414 assertNoErrors(source); 483 assertNoErrors(source);
415 verify([source]); 484 verify([source]);
416 } 485 }
417 486
418 void test_constConstructorWithFieldInitializedByNonConst() { 487 void test_constConstructorWithFieldInitializedByNonConst() {
419 Source source = addSource(EngineTestCase.createSource([ 488 Source source = addSource(r'''
420 "class A {", 489 class A {
421 " final int i = f();", 490 final int i = f();
422 " const A();", 491 const A();
423 "}", 492 }
424 "int f() {", 493 int f() {
425 " return 3;", 494 return 3;
426 "}"])); 495 }''');
427 resolve(source); 496 resolve(source);
428 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INIT IALIZED_BY_NON_CONST]); 497 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INIT IALIZED_BY_NON_CONST]);
429 verify([source]); 498 verify([source]);
430 } 499 }
431 500
432 void test_constConstructorWithFieldInitializedByNonConst_static() { 501 void test_constConstructorWithFieldInitializedByNonConst_static() {
433 Source source = addSource(EngineTestCase.createSource([ 502 Source source = addSource(r'''
434 "class A {", 503 class A {
435 " static final int i = f();", 504 static final int i = f();
436 " const A();", 505 const A();
437 "}", 506 }
438 "int f() {", 507 int f() {
439 " return 3;", 508 return 3;
440 "}"])); 509 }''');
441 resolve(source); 510 resolve(source);
442 assertNoErrors(source); 511 assertNoErrors(source);
443 verify([source]); 512 verify([source]);
444 } 513 }
445 514
446 void test_constConstructorWithMixin() { 515 void test_constConstructorWithMixin() {
447 Source source = addSource(EngineTestCase.createSource([ 516 Source source = addSource(r'''
448 "class M {", 517 class M {
449 "}", 518 }
450 "class A extends Object with M {", 519 class A extends Object with M {
451 " const A();", 520 const A();
452 "}"])); 521 }''');
453 resolve(source); 522 resolve(source);
454 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]); 523 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]);
455 verify([source]); 524 verify([source]);
456 } 525 }
457 526
458 void test_constConstructorWithNonConstSuper_explicit() { 527 void test_constConstructorWithNonConstSuper_explicit() {
459 Source source = addSource(EngineTestCase.createSource([ 528 Source source = addSource(r'''
460 "class A {", 529 class A {
461 " A();", 530 A();
462 "}", 531 }
463 "class B extends A {", 532 class B extends A {
464 " const B(): super();", 533 const B(): super();
465 "}"])); 534 }''');
466 resolve(source); 535 resolve(source);
467 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_ SUPER]); 536 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_ SUPER]);
468 verify([source]); 537 verify([source]);
469 } 538 }
470 539
471 void test_constConstructorWithNonConstSuper_implicit() { 540 void test_constConstructorWithNonConstSuper_implicit() {
472 Source source = addSource(EngineTestCase.createSource([ 541 Source source = addSource(r'''
473 "class A {", 542 class A {
474 " A();", 543 A();
475 "}", 544 }
476 "class B extends A {", 545 class B extends A {
477 " const B();", 546 const B();
478 "}"])); 547 }''');
479 resolve(source); 548 resolve(source);
480 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_ SUPER]); 549 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_ SUPER]);
481 verify([source]); 550 verify([source]);
482 } 551 }
483 552
484 void test_constConstructorWithNonFinalField_mixin() { 553 void test_constConstructorWithNonFinalField_mixin() {
485 Source source = addSource(EngineTestCase.createSource([ 554 Source source = addSource(r'''
486 "class A {", 555 class A {
487 " var a;", 556 var a;
488 "}", 557 }
489 "class B extends Object with A {", 558 class B extends Object with A {
490 " const B();", 559 const B();
491 "}"])); 560 }''');
492 resolve(source); 561 resolve(source);
493 assertErrors(source, [ 562 assertErrors(source, [
494 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN, 563 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN,
495 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]); 564 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]);
496 verify([source]); 565 verify([source]);
497 } 566 }
498 567
499 void test_constConstructorWithNonFinalField_super() { 568 void test_constConstructorWithNonFinalField_super() {
500 Source source = addSource(EngineTestCase.createSource([ 569 Source source = addSource(r'''
501 "class A {", 570 class A {
502 " var a;", 571 var a;
503 "}", 572 }
504 "class B extends A {", 573 class B extends A {
505 " const B();", 574 const B();
506 "}"])); 575 }''');
507 resolve(source); 576 resolve(source);
508 assertErrors(source, [ 577 assertErrors(source, [
509 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD, 578 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD,
510 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]); 579 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]);
511 verify([source]); 580 verify([source]);
512 } 581 }
513 582
514 void test_constConstructorWithNonFinalField_this() { 583 void test_constConstructorWithNonFinalField_this() {
515 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " const A();", "}"])); 584 Source source = addSource(r'''
585 class A {
586 int x;
587 const A();
588 }''');
516 resolve(source); 589 resolve(source);
517 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_ FIELD]); 590 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_ FIELD]);
518 verify([source]); 591 verify([source]);
519 } 592 }
520 593
521 void test_constDeferredClass() { 594 void test_constDeferredClass() {
522 resolveWithAndWithoutExperimental(<String> [ 595 resolveWithAndWithoutExperimental(<String> [
523 EngineTestCase.createSource(["library lib1;", "class A {", " const A(); ", "}"]), 596 r'''
524 EngineTestCase.createSource([ 597 library lib1;
525 "library root;", 598 class A {
526 "import 'lib1.dart' deferred as a;", 599 const A();
527 "main() {", 600 }''',
528 " const a.A();", 601 r'''
529 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.CONST_DEFERRED_CLASS]); 602 library root;
603 import 'lib1.dart' deferred as a;
604 main() {
605 const a.A();
606 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.CONST_DEFERRED_CLASS]);
530 } 607 }
531 608
532 void test_constDeferredClass_namedConstructor() { 609 void test_constDeferredClass_namedConstructor() {
533 resolveWithAndWithoutExperimental(<String> [ 610 resolveWithAndWithoutExperimental(<String> [
534 EngineTestCase.createSource(["library lib1;", "class A {", " const A.b( );", "}"]), 611 r'''
535 EngineTestCase.createSource([ 612 library lib1;
536 "library root;", 613 class A {
537 "import 'lib1.dart' deferred as a;", 614 const A.b();
538 "main() {", 615 }''',
539 " const a.A.b();", 616 r'''
540 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.CONST_DEFERRED_CLASS]); 617 library root;
618 import 'lib1.dart' deferred as a;
619 main() {
620 const a.A.b();
621 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.CONST_DEFERRED_CLASS]);
541 } 622 }
542 623
543 void test_constEval_newInstance_constConstructor() { 624 void test_constEval_newInstance_constConstructor() {
544 Source source = addSource(EngineTestCase.createSource(["class A {", " const A();", "}", "const a = new A();"])); 625 Source source = addSource(r'''
626 class A {
627 const A();
628 }
629 const a = new A();''');
545 resolve(source); 630 resolve(source);
546 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]); 631 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]);
547 verify([source]); 632 verify([source]);
548 } 633 }
549 634
550 void test_constEval_newInstance_externalFactoryConstConstructor() { 635 void test_constEval_newInstance_externalFactoryConstConstructor() {
551 // We can't evaluate "const A()" because its constructor is external. But 636 // We can't evaluate "const A()" because its constructor is external. But
552 // the code is correct--we shouldn't report an error. 637 // the code is correct--we shouldn't report an error.
553 Source source = addSource(EngineTestCase.createSource([ 638 Source source = addSource(r'''
554 "class A {", 639 class A {
555 " external factory const A();", 640 external factory const A();
556 "}", 641 }
557 "const x = const A();"])); 642 const x = const A();''');
558 resolve(source); 643 resolve(source);
559 assertNoErrors(source); 644 assertNoErrors(source);
560 verify([source]); 645 verify([source]);
561 } 646 }
562 647
563 void test_constEval_propertyExtraction_targetNotConst() { 648 void test_constEval_propertyExtraction_targetNotConst() {
564 Source source = addSource(EngineTestCase.createSource([ 649 Source source = addSource(r'''
565 "class A {", 650 class A {
566 " const A();", 651 const A();
567 " m() {}", 652 m() {}
568 "}", 653 }
569 "final a = const A();", 654 final a = const A();
570 "const C = a.m;"])); 655 const C = a.m;''');
571 resolve(source); 656 resolve(source);
572 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]); 657 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]);
573 verify([source]); 658 verify([source]);
574 } 659 }
575 660
576 void test_constEvalThrowsException_binaryMinus_null() { 661 void test_constEvalThrowsException_binaryMinus_null() {
577 _check_constEvalThrowsException_binary_null("null - 5", false); 662 _check_constEvalThrowsException_binary_null("null - 5", false);
578 _check_constEvalThrowsException_binary_null("5 - null", true); 663 _check_constEvalThrowsException_binary_null("5 - null", true);
579 } 664 }
580 665
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 Source source = addSource("const C = (true || 0);"); 705 Source source = addSource("const C = (true || 0);");
621 resolve(source); 706 resolve(source);
622 assertErrors(source, [ 707 assertErrors(source, [
623 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 708 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
624 StaticTypeWarningCode.NON_BOOL_OPERAND, 709 StaticTypeWarningCode.NON_BOOL_OPERAND,
625 HintCode.DEAD_CODE]); 710 HintCode.DEAD_CODE]);
626 verify([source]); 711 verify([source]);
627 } 712 }
628 713
629 void test_constEvalTypeBoolNumString_equal() { 714 void test_constEvalTypeBoolNumString_equal() {
630 Source source = addSource(EngineTestCase.createSource([ 715 Source source = addSource(r'''
631 "class A {", 716 class A {
632 " const A();", 717 const A();
633 "}", 718 }
634 "class B {", 719 class B {
635 " final a;", 720 final a;
636 " const B(num p) : a = p == const A();", 721 const B(num p) : a = p == const A();
637 "}"])); 722 }''');
638 resolve(source); 723 resolve(source);
639 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]) ; 724 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]) ;
640 verify([source]); 725 verify([source]);
641 } 726 }
642 727
643 void test_constEvalTypeBoolNumString_notEqual() { 728 void test_constEvalTypeBoolNumString_notEqual() {
644 Source source = addSource(EngineTestCase.createSource([ 729 Source source = addSource(r'''
645 "class A {", 730 class A {
646 " const A();", 731 const A();
647 "}", 732 }
648 "class B {", 733 class B {
649 " final a;", 734 final a;
650 " const B(String p) : a = p != const A();", 735 const B(String p) : a = p != const A();
651 "}"])); 736 }''');
652 resolve(source); 737 resolve(source);
653 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]) ; 738 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]) ;
654 verify([source]); 739 verify([source]);
655 } 740 }
656 741
657 void test_constEvalTypeInt_binary() { 742 void test_constEvalTypeInt_binary() {
658 _check_constEvalTypeInt_withParameter_binary("p ^ ''"); 743 _check_constEvalTypeInt_withParameter_binary("p ^ ''");
659 _check_constEvalTypeInt_withParameter_binary("p & ''"); 744 _check_constEvalTypeInt_withParameter_binary("p & ''");
660 _check_constEvalTypeInt_withParameter_binary("p | ''"); 745 _check_constEvalTypeInt_withParameter_binary("p | ''");
661 _check_constEvalTypeInt_withParameter_binary("p >> ''"); 746 _check_constEvalTypeInt_withParameter_binary("p >> ''");
662 _check_constEvalTypeInt_withParameter_binary("p << ''"); 747 _check_constEvalTypeInt_withParameter_binary("p << ''");
663 } 748 }
664 749
665 void test_constEvalTypeNum_binary() { 750 void test_constEvalTypeNum_binary() {
666 _check_constEvalTypeNum_withParameter_binary("p + ''"); 751 _check_constEvalTypeNum_withParameter_binary("p + ''");
667 _check_constEvalTypeNum_withParameter_binary("p - ''"); 752 _check_constEvalTypeNum_withParameter_binary("p - ''");
668 _check_constEvalTypeNum_withParameter_binary("p * ''"); 753 _check_constEvalTypeNum_withParameter_binary("p * ''");
669 _check_constEvalTypeNum_withParameter_binary("p / ''"); 754 _check_constEvalTypeNum_withParameter_binary("p / ''");
670 _check_constEvalTypeNum_withParameter_binary("p ~/ ''"); 755 _check_constEvalTypeNum_withParameter_binary("p ~/ ''");
671 _check_constEvalTypeNum_withParameter_binary("p > ''"); 756 _check_constEvalTypeNum_withParameter_binary("p > ''");
672 _check_constEvalTypeNum_withParameter_binary("p < ''"); 757 _check_constEvalTypeNum_withParameter_binary("p < ''");
673 _check_constEvalTypeNum_withParameter_binary("p >= ''"); 758 _check_constEvalTypeNum_withParameter_binary("p >= ''");
674 _check_constEvalTypeNum_withParameter_binary("p <= ''"); 759 _check_constEvalTypeNum_withParameter_binary("p <= ''");
675 _check_constEvalTypeNum_withParameter_binary("p % ''"); 760 _check_constEvalTypeNum_withParameter_binary("p % ''");
676 } 761 }
677 762
678 void test_constFormalParameter_fieldFormalParameter() { 763 void test_constFormalParameter_fieldFormalParameter() {
679 Source source = addSource(EngineTestCase.createSource(["class A {", " var x ;", " A(const this.x) {}", "}"])); 764 Source source = addSource(r'''
765 class A {
766 var x;
767 A(const this.x) {}
768 }''');
680 resolve(source); 769 resolve(source);
681 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); 770 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]);
682 verify([source]); 771 verify([source]);
683 } 772 }
684 773
685 void test_constFormalParameter_simpleFormalParameter() { 774 void test_constFormalParameter_simpleFormalParameter() {
686 Source source = addSource(EngineTestCase.createSource(["f(const x) {}"])); 775 Source source = addSource("f(const x) {}");
687 resolve(source); 776 resolve(source);
688 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); 777 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]);
689 verify([source]); 778 verify([source]);
690 } 779 }
691 780
692 void test_constInitializedWithNonConstValue() { 781 void test_constInitializedWithNonConstValue() {
693 Source source = addSource(EngineTestCase.createSource(["f(p) {", " const C = p;", "}"])); 782 Source source = addSource(r'''
783 f(p) {
784 const C = p;
785 }''');
694 resolve(source); 786 resolve(source);
695 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]); 787 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]);
696 verify([source]); 788 verify([source]);
697 } 789 }
698 790
699 void test_constInitializedWithNonConstValue_missingConstInListLiteral() { 791 void test_constInitializedWithNonConstValue_missingConstInListLiteral() {
700 Source source = addSource("const List L = [0];"); 792 Source source = addSource("const List L = [0];");
701 resolve(source); 793 resolve(source);
702 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]); 794 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]);
703 verify([source]); 795 verify([source]);
704 } 796 }
705 797
706 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() { 798 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() {
707 Source source = addSource("const Map M = {'a' : 0};"); 799 Source source = addSource("const Map M = {'a' : 0};");
708 resolve(source); 800 resolve(source);
709 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]); 801 assertErrors(source, [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTA NT_VALUE]);
710 verify([source]); 802 verify([source]);
711 } 803 }
712 804
713 void test_constInitializedWithNonConstValueFromDeferredClass() { 805 void test_constInitializedWithNonConstValueFromDeferredClass() {
714 resolveWithAndWithoutExperimental(<String> [ 806 resolveWithAndWithoutExperimental(<String> [
715 EngineTestCase.createSource(["library lib1;", "const V = 1;"]), 807 r'''
716 EngineTestCase.createSource([ 808 library lib1;
717 "library root;", 809 const V = 1;''',
718 "import 'lib1.dart' deferred as a;", 810 r'''
719 "const B = a.V;"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_S UPPORTED], <ErrorCode> [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT _VALUE_FROM_DEFERRED_LIBRARY]); 811 library root;
812 import 'lib1.dart' deferred as a;
813 const B = a.V;'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED] , <ErrorCode> [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FR OM_DEFERRED_LIBRARY]);
720 } 814 }
721 815
722 void test_constInitializedWithNonConstValueFromDeferredClass_nested() { 816 void test_constInitializedWithNonConstValueFromDeferredClass_nested() {
723 resolveWithAndWithoutExperimental(<String> [ 817 resolveWithAndWithoutExperimental(<String> [
724 EngineTestCase.createSource(["library lib1;", "const V = 1;"]), 818 r'''
725 EngineTestCase.createSource([ 819 library lib1;
726 "library root;", 820 const V = 1;''',
727 "import 'lib1.dart' deferred as a;", 821 r'''
728 "const B = a.V + 1;"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_N OT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONS TANT_VALUE_FROM_DEFERRED_LIBRARY]); 822 library root;
823 import 'lib1.dart' deferred as a;
824 const B = a.V + 1;'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPOR TED], <ErrorCode> [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALU E_FROM_DEFERRED_LIBRARY]);
729 } 825 }
730 826
731 void test_constInstanceField() { 827 void test_constInstanceField() {
732 Source source = addSource(EngineTestCase.createSource(["class C {", " const int f = 0;", "}"])); 828 Source source = addSource(r'''
829 class C {
830 const int f = 0;
831 }''');
733 resolve(source); 832 resolve(source);
734 assertErrors(source, [CompileTimeErrorCode.CONST_INSTANCE_FIELD]); 833 assertErrors(source, [CompileTimeErrorCode.CONST_INSTANCE_FIELD]);
735 verify([source]); 834 verify([source]);
736 } 835 }
737 836
738 void test_constMapKeyTypeImplementsEquals_direct() { 837 void test_constMapKeyTypeImplementsEquals_direct() {
739 Source source = addSource(EngineTestCase.createSource([ 838 Source source = addSource(r'''
740 "class A {", 839 class A {
741 " const A();", 840 const A();
742 " operator ==(other) => false;", 841 operator ==(other) => false;
743 "}", 842 }
744 "main() {", 843 main() {
745 " const {const A() : 0};", 844 const {const A() : 0};
746 "}"])); 845 }''');
747 resolve(source); 846 resolve(source);
748 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP LEMENTS_EQUALS]); 847 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP LEMENTS_EQUALS]);
749 verify([source]); 848 verify([source]);
750 } 849 }
751 850
752 void test_constMapKeyTypeImplementsEquals_dynamic() { 851 void test_constMapKeyTypeImplementsEquals_dynamic() {
753 // Note: static type of B.a is "dynamic", but actual type of the const 852 // Note: static type of B.a is "dynamic", but actual type of the const
754 // object is A. We need to make sure we examine the actual type when 853 // object is A. We need to make sure we examine the actual type when
755 // deciding whether there is a problem with operator==. 854 // deciding whether there is a problem with operator==.
756 Source source = addSource(EngineTestCase.createSource([ 855 Source source = addSource(r'''
757 "class A {", 856 class A {
758 " const A();", 857 const A();
759 " operator ==(other) => false;", 858 operator ==(other) => false;
760 "}", 859 }
761 "class B {", 860 class B {
762 " static const a = const A();", 861 static const a = const A();
763 "}", 862 }
764 "main() {", 863 main() {
765 " const {B.a : 0};", 864 const {B.a : 0};
766 "}"])); 865 }''');
767 resolve(source); 866 resolve(source);
768 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP LEMENTS_EQUALS]); 867 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP LEMENTS_EQUALS]);
769 verify([source]); 868 verify([source]);
770 } 869 }
771 870
772 void test_constMapKeyTypeImplementsEquals_factory() { 871 void test_constMapKeyTypeImplementsEquals_factory() {
773 Source source = addSource(EngineTestCase.createSource([ 872 Source source = addSource(r'''
774 "class A { const factory A() = B; }", 873 class A { const factory A() = B; }
775 "", 874
776 "class B implements A {", 875 class B implements A {
777 " const B();", 876 const B();
778 "", 877
779 " operator ==(o) => true;", 878 operator ==(o) => true;
780 "}", 879 }
781 "", 880
782 "main() {", 881 main() {
783 " var m = const { const A(): 42 };", 882 var m = const { const A(): 42 };
784 "}"])); 883 }''');
785 resolve(source); 884 resolve(source);
786 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP LEMENTS_EQUALS]); 885 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP LEMENTS_EQUALS]);
787 verify([source]); 886 verify([source]);
788 } 887 }
789 888
790 void test_constMapKeyTypeImplementsEquals_super() { 889 void test_constMapKeyTypeImplementsEquals_super() {
791 Source source = addSource(EngineTestCase.createSource([ 890 Source source = addSource(r'''
792 "class A {", 891 class A {
793 " const A();", 892 const A();
794 " operator ==(other) => false;", 893 operator ==(other) => false;
795 "}", 894 }
796 "class B extends A {", 895 class B extends A {
797 " const B();", 896 const B();
798 "}", 897 }
799 "main() {", 898 main() {
800 " const {const B() : 0};", 899 const {const B() : 0};
801 "}"])); 900 }''');
802 resolve(source); 901 resolve(source);
803 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP LEMENTS_EQUALS]); 902 assertErrors(source, [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMP LEMENTS_EQUALS]);
804 verify([source]); 903 verify([source]);
805 } 904 }
806 905
807 void test_constWithInvalidTypeParameters() { 906 void test_constWithInvalidTypeParameters() {
808 Source source = addSource(EngineTestCase.createSource([ 907 Source source = addSource(r'''
809 "class A {", 908 class A {
810 " const A();", 909 const A();
811 "}", 910 }
812 "f() { return const A<A>(); }"])); 911 f() { return const A<A>(); }''');
813 resolve(source); 912 resolve(source);
814 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETER S]); 913 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETER S]);
815 verify([source]); 914 verify([source]);
816 } 915 }
817 916
818 void test_constWithInvalidTypeParameters_tooFew() { 917 void test_constWithInvalidTypeParameters_tooFew() {
819 Source source = addSource(EngineTestCase.createSource([ 918 Source source = addSource(r'''
820 "class A {}", 919 class A {}
821 "class C<K, V> {", 920 class C<K, V> {
822 " const C();", 921 const C();
823 "}", 922 }
824 "f(p) {", 923 f(p) {
825 " return const C<A>();", 924 return const C<A>();
826 "}"])); 925 }''');
827 resolve(source); 926 resolve(source);
828 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETER S]); 927 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETER S]);
829 verify([source]); 928 verify([source]);
830 } 929 }
831 930
832 void test_constWithInvalidTypeParameters_tooMany() { 931 void test_constWithInvalidTypeParameters_tooMany() {
833 Source source = addSource(EngineTestCase.createSource([ 932 Source source = addSource(r'''
834 "class A {}", 933 class A {}
835 "class C<E> {", 934 class C<E> {
836 " const C();", 935 const C();
837 "}", 936 }
838 "f(p) {", 937 f(p) {
839 " return const C<A, A>();", 938 return const C<A, A>();
840 "}"])); 939 }''');
841 resolve(source); 940 resolve(source);
842 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETER S]); 941 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETER S]);
843 verify([source]); 942 verify([source]);
844 } 943 }
845 944
846 void test_constWithNonConst() { 945 void test_constWithNonConst() {
847 Source source = addSource(EngineTestCase.createSource([ 946 Source source = addSource(r'''
848 "class T {", 947 class T {
849 " T(a, b, {c, d}) {}", 948 T(a, b, {c, d}) {}
850 "}", 949 }
851 "f() { return const T(0, 1, c: 2, d: 3); }"])); 950 f() { return const T(0, 1, c: 2, d: 3); }''');
852 resolve(source); 951 resolve(source);
853 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]); 952 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]);
854 verify([source]); 953 verify([source]);
855 } 954 }
856 955
857 void test_constWithNonConstantArgument_annotation() { 956 void test_constWithNonConstantArgument_annotation() {
858 Source source = addSource(EngineTestCase.createSource([ 957 Source source = addSource(r'''
859 "class A {", 958 class A {
860 " const A(int p);", 959 const A(int p);
861 "}", 960 }
862 "var v = 42;", 961 var v = 42;
863 "@A(v)", 962 @A(v)
864 "main() {", 963 main() {
865 "}"])); 964 }''');
866 resolve(source); 965 resolve(source);
867 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT] ); 966 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT] );
868 verify([source]); 967 verify([source]);
869 } 968 }
870 969
871 void test_constWithNonConstantArgument_instanceCreation() { 970 void test_constWithNonConstantArgument_instanceCreation() {
872 Source source = addSource(EngineTestCase.createSource([ 971 Source source = addSource(r'''
873 "class A {", 972 class A {
874 " const A(a);", 973 const A(a);
875 "}", 974 }
876 "f(p) { return const A(p); }"])); 975 f(p) { return const A(p); }''');
877 resolve(source); 976 resolve(source);
878 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT] ); 977 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT] );
879 verify([source]); 978 verify([source]);
880 } 979 }
881 980
882 void test_constWithNonType() { 981 void test_constWithNonType() {
883 Source source = addSource(EngineTestCase.createSource(["int A;", "f() {", " return const A();", "}"])); 982 Source source = addSource(r'''
983 int A;
984 f() {
985 return const A();
986 }''');
884 resolve(source); 987 resolve(source);
885 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); 988 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]);
886 verify([source]); 989 verify([source]);
887 } 990 }
888 991
889 void test_constWithNonType_fromLibrary() { 992 void test_constWithNonType_fromLibrary() {
890 Source source1 = addNamedSource("lib.dart", ""); 993 Source source1 = addNamedSource("lib.dart", "");
891 Source source2 = addNamedSource("lib2.dart", EngineTestCase.createSource([ 994 Source source2 = addNamedSource("lib2.dart", r'''
892 "import 'lib.dart' as lib;", 995 import 'lib.dart' as lib;
893 "void f() {", 996 void f() {
894 " const lib.A();", 997 const lib.A();
895 "}"])); 998 }''');
896 resolve(source1); 999 resolve(source1);
897 resolve(source2); 1000 resolve(source2);
898 assertErrors(source2, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); 1001 assertErrors(source2, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]);
899 verify([source1]); 1002 verify([source1]);
900 } 1003 }
901 1004
902 void test_constWithTypeParameters_direct() { 1005 void test_constWithTypeParameters_direct() {
903 Source source = addSource(EngineTestCase.createSource([ 1006 Source source = addSource(r'''
904 "class A<T> {", 1007 class A<T> {
905 " static const V = const A<T>();", 1008 static const V = const A<T>();
906 " const A();", 1009 const A();
907 "}"])); 1010 }''');
908 resolve(source); 1011 resolve(source);
909 assertErrors(source, [ 1012 assertErrors(source, [
910 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 1013 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS,
911 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); 1014 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
912 verify([source]); 1015 verify([source]);
913 } 1016 }
914 1017
915 void test_constWithTypeParameters_indirect() { 1018 void test_constWithTypeParameters_indirect() {
916 Source source = addSource(EngineTestCase.createSource([ 1019 Source source = addSource(r'''
917 "class A<T> {", 1020 class A<T> {
918 " static const V = const A<List<T>>();", 1021 static const V = const A<List<T>>();
919 " const A();", 1022 const A();
920 "}"])); 1023 }''');
921 resolve(source); 1024 resolve(source);
922 assertErrors(source, [ 1025 assertErrors(source, [
923 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 1026 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS,
924 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); 1027 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
925 verify([source]); 1028 verify([source]);
926 } 1029 }
927 1030
928 void test_constWithUndefinedConstructor() { 1031 void test_constWithUndefinedConstructor() {
929 Source source = addSource(EngineTestCase.createSource([ 1032 Source source = addSource(r'''
930 "class A {", 1033 class A {
931 " const A();", 1034 const A();
932 "}", 1035 }
933 "f() {", 1036 f() {
934 " return const A.noSuchConstructor();", 1037 return const A.noSuchConstructor();
935 "}"])); 1038 }''');
936 resolve(source); 1039 resolve(source);
937 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR] ); 1040 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR] );
938 // no verify(), 'noSuchConstructor' is not resolved 1041 // no verify(), 'noSuchConstructor' is not resolved
939 } 1042 }
940 1043
941 void test_constWithUndefinedConstructorDefault() { 1044 void test_constWithUndefinedConstructorDefault() {
942 Source source = addSource(EngineTestCase.createSource([ 1045 Source source = addSource(r'''
943 "class A {", 1046 class A {
944 " const A.name();", 1047 const A.name();
945 "}", 1048 }
946 "f() {", 1049 f() {
947 " return const A();", 1050 return const A();
948 "}"])); 1051 }''');
949 resolve(source); 1052 resolve(source);
950 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_ DEFAULT]); 1053 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_ DEFAULT]);
951 verify([source]); 1054 verify([source]);
952 } 1055 }
953 1056
954 void test_defaultValueInFunctionTypeAlias() { 1057 void test_defaultValueInFunctionTypeAlias() {
955 Source source = addSource(EngineTestCase.createSource(["typedef F([x = 0]);" ])); 1058 Source source = addSource("typedef F([x = 0]);");
956 resolve(source); 1059 resolve(source);
957 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_AL IAS]); 1060 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_AL IAS]);
958 verify([source]); 1061 verify([source]);
959 } 1062 }
960 1063
961 void test_defaultValueInFunctionTypedParameter_named() { 1064 void test_defaultValueInFunctionTypedParameter_named() {
962 Source source = addSource(EngineTestCase.createSource(["f(g({p: null})) {}"] )); 1065 Source source = addSource("f(g({p: null})) {}");
963 resolve(source); 1066 resolve(source);
964 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_P ARAMETER]); 1067 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_P ARAMETER]);
965 verify([source]); 1068 verify([source]);
966 } 1069 }
967 1070
968 void test_defaultValueInFunctionTypedParameter_optional() { 1071 void test_defaultValueInFunctionTypedParameter_optional() {
969 Source source = addSource(EngineTestCase.createSource(["f(g([p = null])) {}" ])); 1072 Source source = addSource("f(g([p = null])) {}");
970 resolve(source); 1073 resolve(source);
971 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_P ARAMETER]); 1074 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_P ARAMETER]);
972 verify([source]); 1075 verify([source]);
973 } 1076 }
974 1077
975 void test_defaultValueInRedirectingFactoryConstructor() { 1078 void test_defaultValueInRedirectingFactoryConstructor() {
976 Source source = addSource(EngineTestCase.createSource([ 1079 Source source = addSource(r'''
977 "class A {", 1080 class A {
978 " factory A([int x = 0]) = B;", 1081 factory A([int x = 0]) = B;
979 "}", 1082 }
980 "", 1083
981 "class B implements A {", 1084 class B implements A {
982 " B([int x = 1]) {}", 1085 B([int x = 1]) {}
983 "}"])); 1086 }''');
984 resolve(source); 1087 resolve(source);
985 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_REDIRECTING_FACT ORY_CONSTRUCTOR]); 1088 assertErrors(source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_REDIRECTING_FACT ORY_CONSTRUCTOR]);
986 verify([source]); 1089 verify([source]);
987 } 1090 }
988 1091
989 void test_duplicateConstructorName_named() { 1092 void test_duplicateConstructorName_named() {
990 Source source = addSource(EngineTestCase.createSource(["class A {", " A.a() {}", " A.a() {}", "}"])); 1093 Source source = addSource(r'''
1094 class A {
1095 A.a() {}
1096 A.a() {}
1097 }''');
991 resolve(source); 1098 resolve(source);
992 assertErrors(source, [ 1099 assertErrors(source, [
993 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, 1100 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME,
994 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME]); 1101 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME]);
995 verify([source]); 1102 verify([source]);
996 } 1103 }
997 1104
998 void test_duplicateConstructorName_unnamed() { 1105 void test_duplicateConstructorName_unnamed() {
999 Source source = addSource(EngineTestCase.createSource(["class A {", " A() { }", " A() {}", "}"])); 1106 Source source = addSource(r'''
1107 class A {
1108 A() {}
1109 A() {}
1110 }''');
1000 resolve(source); 1111 resolve(source);
1001 assertErrors(source, [ 1112 assertErrors(source, [
1002 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, 1113 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT,
1003 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT]); 1114 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT]);
1004 verify([source]); 1115 verify([source]);
1005 } 1116 }
1006 1117
1007 void test_duplicateDefinition() { 1118 void test_duplicateDefinition() {
1008 Source source = addSource(EngineTestCase.createSource(["f() {", " int m = 0 ;", " m(a) {}", "}"])); 1119 Source source = addSource(r'''
1120 f() {
1121 int m = 0;
1122 m(a) {}
1123 }''');
1009 resolve(source); 1124 resolve(source);
1010 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1125 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1011 verify([source]); 1126 verify([source]);
1012 } 1127 }
1013 1128
1014 void test_duplicateDefinition_acrossLibraries() { 1129 void test_duplicateDefinition_acrossLibraries() {
1015 Source librarySource = addNamedSource("/lib.dart", EngineTestCase.createSour ce(["library lib;", "", "part 'a.dart';", "part 'b.dart';"])); 1130 Source librarySource = addNamedSource("/lib.dart", r'''
1016 Source sourceA = addNamedSource("/a.dart", EngineTestCase.createSource(["par t of lib;", "", "class A {}"])); 1131 library lib;
1017 Source sourceB = addNamedSource("/b.dart", EngineTestCase.createSource(["par t of lib;", "", "class A {}"])); 1132
1133 part 'a.dart';
1134 part 'b.dart';''');
1135 Source sourceA = addNamedSource("/a.dart", r'''
1136 part of lib;
1137
1138 class A {}''');
1139 Source sourceB = addNamedSource("/b.dart", r'''
1140 part of lib;
1141
1142 class A {}''');
1018 resolve(librarySource); 1143 resolve(librarySource);
1019 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1144 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1020 verify([librarySource, sourceA, sourceB]); 1145 verify([librarySource, sourceA, sourceB]);
1021 } 1146 }
1022 1147
1023 void test_duplicateDefinition_classMembers_fields() { 1148 void test_duplicateDefinition_classMembers_fields() {
1024 Source source = addSource(EngineTestCase.createSource(["class A {", " int a ;", " int a;", "}"])); 1149 Source source = addSource(r'''
1150 class A {
1151 int a;
1152 int a;
1153 }''');
1025 resolve(source); 1154 resolve(source);
1026 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1155 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1027 verify([source]); 1156 verify([source]);
1028 } 1157 }
1029 1158
1030 void test_duplicateDefinition_classMembers_fields_oneStatic() { 1159 void test_duplicateDefinition_classMembers_fields_oneStatic() {
1031 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " static int x;", "}"])); 1160 Source source = addSource(r'''
1161 class A {
1162 int x;
1163 static int x;
1164 }''');
1032 resolve(source); 1165 resolve(source);
1033 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1166 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1034 verify([source]); 1167 verify([source]);
1035 } 1168 }
1036 1169
1037 void test_duplicateDefinition_classMembers_methods() { 1170 void test_duplicateDefinition_classMembers_methods() {
1038 Source source = addSource(EngineTestCase.createSource(["class A {", " m() { }", " m() {}", "}"])); 1171 Source source = addSource(r'''
1172 class A {
1173 m() {}
1174 m() {}
1175 }''');
1039 resolve(source); 1176 resolve(source);
1040 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1177 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1041 verify([source]); 1178 verify([source]);
1042 } 1179 }
1043 1180
1044 void test_duplicateDefinition_localFields() { 1181 void test_duplicateDefinition_localFields() {
1045 Source source = addSource(EngineTestCase.createSource([ 1182 Source source = addSource(r'''
1046 "class A {", 1183 class A {
1047 " m() {", 1184 m() {
1048 " int a;", 1185 int a;
1049 " int a;", 1186 int a;
1050 " }", 1187 }
1051 "}"])); 1188 }''');
1052 resolve(source); 1189 resolve(source);
1053 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1190 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1054 verify([source]); 1191 verify([source]);
1055 } 1192 }
1056 1193
1057 void test_duplicateDefinition_parameterWithFunctionName_local() { 1194 void test_duplicateDefinition_parameterWithFunctionName_local() {
1058 Source source = addSource(EngineTestCase.createSource(["main() {", " f(f) { }", "}"])); 1195 Source source = addSource(r'''
1196 main() {
1197 f(f) {}
1198 }''');
1059 resolve(source); 1199 resolve(source);
1060 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1200 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1061 verify([source]); 1201 verify([source]);
1062 } 1202 }
1063 1203
1064 void test_duplicateDefinition_parameterWithFunctionName_topLevel() { 1204 void test_duplicateDefinition_parameterWithFunctionName_topLevel() {
1065 Source source = addSource(EngineTestCase.createSource(["main() {", " f(f) { }", "}"])); 1205 Source source = addSource(r'''
1206 main() {
1207 f(f) {}
1208 }''');
1066 resolve(source); 1209 resolve(source);
1067 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1210 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1068 verify([source]); 1211 verify([source]);
1069 } 1212 }
1070 1213
1071 void test_duplicateDefinitionInheritance_instanceGetter_staticGetter() { 1214 void test_duplicateDefinitionInheritance_instanceGetter_staticGetter() {
1072 Source source = addSource(EngineTestCase.createSource([ 1215 Source source = addSource(r'''
1073 "class A {", 1216 class A {
1074 " int get x => 0;", 1217 int get x => 0;
1075 "}", 1218 }
1076 "class B extends A {", 1219 class B extends A {
1077 " static int get x => 0;", 1220 static int get x => 0;
1078 "}"])); 1221 }''');
1079 resolve(source); 1222 resolve(source);
1080 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] ); 1223 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] );
1081 verify([source]); 1224 verify([source]);
1082 } 1225 }
1083 1226
1084 void test_duplicateDefinitionInheritance_instanceGetterAbstract_staticGetter() { 1227 void test_duplicateDefinitionInheritance_instanceGetterAbstract_staticGetter() {
1085 Source source = addSource(EngineTestCase.createSource([ 1228 Source source = addSource(r'''
1086 "abstract class A {", 1229 abstract class A {
1087 " int get x;", 1230 int get x;
1088 "}", 1231 }
1089 "class B extends A {", 1232 class B extends A {
1090 " static int get x => 0;", 1233 static int get x => 0;
1091 "}"])); 1234 }''');
1092 resolve(source); 1235 resolve(source);
1093 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] ); 1236 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] );
1094 verify([source]); 1237 verify([source]);
1095 } 1238 }
1096 1239
1097 void test_duplicateDefinitionInheritance_instanceMethod_staticMethod() { 1240 void test_duplicateDefinitionInheritance_instanceMethod_staticMethod() {
1098 Source source = addSource(EngineTestCase.createSource([ 1241 Source source = addSource(r'''
1099 "class A {", 1242 class A {
1100 " x() {}", 1243 x() {}
1101 "}", 1244 }
1102 "class B extends A {", 1245 class B extends A {
1103 " static x() {}", 1246 static x() {}
1104 "}"])); 1247 }''');
1105 resolve(source); 1248 resolve(source);
1106 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] ); 1249 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] );
1107 verify([source]); 1250 verify([source]);
1108 } 1251 }
1109 1252
1110 void test_duplicateDefinitionInheritance_instanceMethodAbstract_staticMethod() { 1253 void test_duplicateDefinitionInheritance_instanceMethodAbstract_staticMethod() {
1111 Source source = addSource(EngineTestCase.createSource([ 1254 Source source = addSource(r'''
1112 "abstract class A {", 1255 abstract class A {
1113 " x();", 1256 x();
1114 "}", 1257 }
1115 "abstract class B extends A {", 1258 abstract class B extends A {
1116 " static x() {}", 1259 static x() {}
1117 "}"])); 1260 }''');
1118 resolve(source); 1261 resolve(source);
1119 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] ); 1262 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] );
1120 verify([source]); 1263 verify([source]);
1121 } 1264 }
1122 1265
1123 void test_duplicateDefinitionInheritance_instanceSetter_staticSetter() { 1266 void test_duplicateDefinitionInheritance_instanceSetter_staticSetter() {
1124 Source source = addSource(EngineTestCase.createSource([ 1267 Source source = addSource(r'''
1125 "class A {", 1268 class A {
1126 " set x(value) {}", 1269 set x(value) {}
1127 "}", 1270 }
1128 "class B extends A {", 1271 class B extends A {
1129 " static set x(value) {}", 1272 static set x(value) {}
1130 "}"])); 1273 }''');
1131 resolve(source); 1274 resolve(source);
1132 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] ); 1275 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] );
1133 verify([source]); 1276 verify([source]);
1134 } 1277 }
1135 1278
1136 void test_duplicateDefinitionInheritance_instanceSetterAbstract_staticSetter() { 1279 void test_duplicateDefinitionInheritance_instanceSetterAbstract_staticSetter() {
1137 Source source = addSource(EngineTestCase.createSource([ 1280 Source source = addSource(r'''
1138 "abstract class A {", 1281 abstract class A {
1139 " set x(value);", 1282 set x(value);
1140 "}", 1283 }
1141 "class B extends A {", 1284 class B extends A {
1142 " static set x(value) {}", 1285 static set x(value) {}
1143 "}"])); 1286 }''');
1144 resolve(source); 1287 resolve(source);
1145 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] ); 1288 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE] );
1146 verify([source]); 1289 verify([source]);
1147 } 1290 }
1148 1291
1149 void test_duplicateNamedArgument() { 1292 void test_duplicateNamedArgument() {
1150 Source source = addSource(EngineTestCase.createSource(["f({a, b}) {}", "main () {", " f(a: 1, a: 2);", "}"])); 1293 Source source = addSource(r'''
1294 f({a, b}) {}
1295 main() {
1296 f(a: 1, a: 2);
1297 }''');
1151 resolve(source); 1298 resolve(source);
1152 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT]); 1299 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT]);
1153 verify([source]); 1300 verify([source]);
1154 } 1301 }
1155 1302
1156 void test_exportInternalLibrary() { 1303 void test_exportInternalLibrary() {
1157 Source source = addSource(EngineTestCase.createSource(["export 'dart:_interc eptors';"])); 1304 Source source = addSource("export 'dart:_interceptors';");
1158 resolve(source); 1305 resolve(source);
1159 assertErrors(source, [CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY]); 1306 assertErrors(source, [CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY]);
1160 verify([source]); 1307 verify([source]);
1161 } 1308 }
1162 1309
1163 void test_exportOfNonLibrary() { 1310 void test_exportOfNonLibrary() {
1164 Source source = addSource(EngineTestCase.createSource(["library L;", "export 'lib1.dart';"])); 1311 Source source = addSource(r'''
1165 addNamedSource("/lib1.dart", EngineTestCase.createSource(["part of lib;"])); 1312 library L;
1313 export 'lib1.dart';''');
1314 addNamedSource("/lib1.dart", "part of lib;");
1166 resolve(source); 1315 resolve(source);
1167 assertErrors(source, [CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); 1316 assertErrors(source, [CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]);
1168 verify([source]); 1317 verify([source]);
1169 } 1318 }
1170 1319
1171 void test_extendsDeferredClass() { 1320 void test_extendsDeferredClass() {
1172 resolveWithAndWithoutExperimental(<String> [ 1321 resolveWithAndWithoutExperimental(<String> [
1173 EngineTestCase.createSource(["library lib1;", "class A {}"]), 1322 r'''
1174 EngineTestCase.createSource([ 1323 library lib1;
1175 "library root;", 1324 class A {}''',
1176 "import 'lib1.dart' deferred as a;", 1325 r'''
1177 "class B extends a.A {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPOR TS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]); 1326 library root;
1327 import 'lib1.dart' deferred as a;
1328 class B extends a.A {}'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SU PPORTED], <ErrorCode> [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]);
1178 } 1329 }
1179 1330
1180 void test_extendsDeferredClass_classTypeAlias() { 1331 void test_extendsDeferredClass_classTypeAlias() {
1181 resolveWithAndWithoutExperimental(<String> [ 1332 resolveWithAndWithoutExperimental(<String> [
1182 EngineTestCase.createSource(["library lib1;", "class A {}"]), 1333 r'''
1183 EngineTestCase.createSource([ 1334 library lib1;
1184 "library root;", 1335 class A {}''',
1185 "import 'lib1.dart' deferred as a;", 1336 r'''
1186 "class M {}", 1337 library root;
1187 "class C = a.A with M;"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORT S_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]); 1338 import 'lib1.dart' deferred as a;
1339 class M {}
1340 class C = a.A with M;'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUP PORTED], <ErrorCode> [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]);
1188 } 1341 }
1189 1342
1190 void test_extendsDisallowedClass_class_bool() { 1343 void test_extendsDisallowedClass_class_bool() {
1191 Source source = addSource(EngineTestCase.createSource(["class A extends bool {}"])); 1344 Source source = addSource("class A extends bool {}");
1192 resolve(source); 1345 resolve(source);
1193 assertErrors(source, [ 1346 assertErrors(source, [
1194 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1347 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1195 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 1348 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
1196 verify([source]); 1349 verify([source]);
1197 } 1350 }
1198 1351
1199 void test_extendsDisallowedClass_class_double() { 1352 void test_extendsDisallowedClass_class_double() {
1200 Source source = addSource(EngineTestCase.createSource(["class A extends doub le {}"])); 1353 Source source = addSource("class A extends double {}");
1201 resolve(source); 1354 resolve(source);
1202 assertErrors(source, [ 1355 assertErrors(source, [
1203 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1356 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1204 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 1357 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
1205 verify([source]); 1358 verify([source]);
1206 } 1359 }
1207 1360
1208 void test_extendsDisallowedClass_class_int() { 1361 void test_extendsDisallowedClass_class_int() {
1209 Source source = addSource(EngineTestCase.createSource(["class A extends int {}"])); 1362 Source source = addSource("class A extends int {}");
1210 resolve(source); 1363 resolve(source);
1211 assertErrors(source, [ 1364 assertErrors(source, [
1212 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1365 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1213 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 1366 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
1214 verify([source]); 1367 verify([source]);
1215 } 1368 }
1216 1369
1217 void test_extendsDisallowedClass_class_Null() { 1370 void test_extendsDisallowedClass_class_Null() {
1218 Source source = addSource(EngineTestCase.createSource(["class A extends Null {}"])); 1371 Source source = addSource("class A extends Null {}");
1219 resolve(source); 1372 resolve(source);
1220 assertErrors(source, [ 1373 assertErrors(source, [
1221 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1374 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1222 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 1375 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
1223 verify([source]); 1376 verify([source]);
1224 } 1377 }
1225 1378
1226 void test_extendsDisallowedClass_class_num() { 1379 void test_extendsDisallowedClass_class_num() {
1227 Source source = addSource(EngineTestCase.createSource(["class A extends num {}"])); 1380 Source source = addSource("class A extends num {}");
1228 resolve(source); 1381 resolve(source);
1229 assertErrors(source, [ 1382 assertErrors(source, [
1230 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1383 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1231 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 1384 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
1232 verify([source]); 1385 verify([source]);
1233 } 1386 }
1234 1387
1235 void test_extendsDisallowedClass_class_String() { 1388 void test_extendsDisallowedClass_class_String() {
1236 Source source = addSource(EngineTestCase.createSource(["class A extends Stri ng {}"])); 1389 Source source = addSource("class A extends String {}");
1237 resolve(source); 1390 resolve(source);
1238 assertErrors(source, [ 1391 assertErrors(source, [
1239 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1392 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1240 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 1393 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
1241 verify([source]); 1394 verify([source]);
1242 } 1395 }
1243 1396
1244 void test_extendsDisallowedClass_classTypeAlias_bool() { 1397 void test_extendsDisallowedClass_classTypeAlias_bool() {
1245 Source source = addSource(EngineTestCase.createSource(["class M {}", "class C = bool with M;"])); 1398 Source source = addSource(r'''
1399 class M {}
1400 class C = bool with M;''');
1246 resolve(source); 1401 resolve(source);
1247 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1402 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
1248 verify([source]); 1403 verify([source]);
1249 } 1404 }
1250 1405
1251 void test_extendsDisallowedClass_classTypeAlias_double() { 1406 void test_extendsDisallowedClass_classTypeAlias_double() {
1252 Source source = addSource(EngineTestCase.createSource(["class M {}", "class C = double with M;"])); 1407 Source source = addSource(r'''
1408 class M {}
1409 class C = double with M;''');
1253 resolve(source); 1410 resolve(source);
1254 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1411 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
1255 verify([source]); 1412 verify([source]);
1256 } 1413 }
1257 1414
1258 void test_extendsDisallowedClass_classTypeAlias_int() { 1415 void test_extendsDisallowedClass_classTypeAlias_int() {
1259 Source source = addSource(EngineTestCase.createSource(["class M {}", "class C = int with M;"])); 1416 Source source = addSource(r'''
1417 class M {}
1418 class C = int with M;''');
1260 resolve(source); 1419 resolve(source);
1261 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1420 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
1262 verify([source]); 1421 verify([source]);
1263 } 1422 }
1264 1423
1265 void test_extendsDisallowedClass_classTypeAlias_Null() { 1424 void test_extendsDisallowedClass_classTypeAlias_Null() {
1266 Source source = addSource(EngineTestCase.createSource(["class M {}", "class C = Null with M;"])); 1425 Source source = addSource(r'''
1426 class M {}
1427 class C = Null with M;''');
1267 resolve(source); 1428 resolve(source);
1268 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1429 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
1269 verify([source]); 1430 verify([source]);
1270 } 1431 }
1271 1432
1272 void test_extendsDisallowedClass_classTypeAlias_num() { 1433 void test_extendsDisallowedClass_classTypeAlias_num() {
1273 Source source = addSource(EngineTestCase.createSource(["class M {}", "class C = num with M;"])); 1434 Source source = addSource(r'''
1435 class M {}
1436 class C = num with M;''');
1274 resolve(source); 1437 resolve(source);
1275 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1438 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
1276 verify([source]); 1439 verify([source]);
1277 } 1440 }
1278 1441
1279 void test_extendsDisallowedClass_classTypeAlias_String() { 1442 void test_extendsDisallowedClass_classTypeAlias_String() {
1280 Source source = addSource(EngineTestCase.createSource(["class M {}", "class C = String with M;"])); 1443 Source source = addSource(r'''
1444 class M {}
1445 class C = String with M;''');
1281 resolve(source); 1446 resolve(source);
1282 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1447 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
1283 verify([source]); 1448 verify([source]);
1284 } 1449 }
1285 1450
1286 void test_extendsEnum() { 1451 void test_extendsEnum() {
1287 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); 1452 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
1288 analysisOptions.enableEnum = true; 1453 analysisOptions.enableEnum = true;
1289 resetWithOptions(analysisOptions); 1454 resetWithOptions(analysisOptions);
1290 Source source = addSource(EngineTestCase.createSource(["enum E { ONE }", "cl ass A extends E {}"])); 1455 Source source = addSource(r'''
1456 enum E { ONE }
1457 class A extends E {}''');
1291 resolve(source); 1458 resolve(source);
1292 assertErrors(source, [CompileTimeErrorCode.EXTENDS_ENUM]); 1459 assertErrors(source, [CompileTimeErrorCode.EXTENDS_ENUM]);
1293 verify([source]); 1460 verify([source]);
1294 } 1461 }
1295 1462
1296 void test_extendsNonClass_class() { 1463 void test_extendsNonClass_class() {
1297 Source source = addSource(EngineTestCase.createSource(["int A;", "class B ex tends A {}"])); 1464 Source source = addSource(r'''
1465 int A;
1466 class B extends A {}''');
1298 resolve(source); 1467 resolve(source);
1299 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); 1468 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]);
1300 verify([source]); 1469 verify([source]);
1301 } 1470 }
1302 1471
1303 void test_extendsNonClass_dynamic() { 1472 void test_extendsNonClass_dynamic() {
1304 Source source = addSource(EngineTestCase.createSource(["class B extends dyna mic {}"])); 1473 Source source = addSource("class B extends dynamic {}");
1305 resolve(source); 1474 resolve(source);
1306 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); 1475 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]);
1307 verify([source]); 1476 verify([source]);
1308 } 1477 }
1309 1478
1310 void test_extraPositionalArguments_const() { 1479 void test_extraPositionalArguments_const() {
1311 Source source = addSource(EngineTestCase.createSource([ 1480 Source source = addSource(r'''
1312 "class A {", 1481 class A {
1313 " const A();", 1482 const A();
1314 "}", 1483 }
1315 "main() {", 1484 main() {
1316 " const A(0);", 1485 const A(0);
1317 "}"])); 1486 }''');
1318 resolve(source); 1487 resolve(source);
1319 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); 1488 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]);
1320 verify([source]); 1489 verify([source]);
1321 } 1490 }
1322 1491
1323 void test_extraPositionalArguments_const_super() { 1492 void test_extraPositionalArguments_const_super() {
1324 Source source = addSource(EngineTestCase.createSource([ 1493 Source source = addSource(r'''
1325 "class A {", 1494 class A {
1326 " const A();", 1495 const A();
1327 "}", 1496 }
1328 "class B extends A {", 1497 class B extends A {
1329 " const B() : super(0);", 1498 const B() : super(0);
1330 "}"])); 1499 }''');
1331 resolve(source); 1500 resolve(source);
1332 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); 1501 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]);
1333 verify([source]); 1502 verify([source]);
1334 } 1503 }
1335 1504
1336 void test_fieldInitializedByMultipleInitializers() { 1505 void test_fieldInitializedByMultipleInitializers() {
1337 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " A() : x = 0, x = 1 {}", "}"])); 1506 Source source = addSource(r'''
1507 class A {
1508 int x;
1509 A() : x = 0, x = 1 {}
1510 }''');
1338 resolve(source); 1511 resolve(source);
1339 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INI TIALIZERS]); 1512 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INI TIALIZERS]);
1340 verify([source]); 1513 verify([source]);
1341 } 1514 }
1342 1515
1343 void test_fieldInitializedByMultipleInitializers_multipleInits() { 1516 void test_fieldInitializedByMultipleInitializers_multipleInits() {
1344 Source source = addSource(EngineTestCase.createSource([ 1517 Source source = addSource(r'''
1345 "class A {", 1518 class A {
1346 " int x;", 1519 int x;
1347 " A() : x = 0, x = 1, x = 2 {}", 1520 A() : x = 0, x = 1, x = 2 {}
1348 "}"])); 1521 }''');
1349 resolve(source); 1522 resolve(source);
1350 assertErrors(source, [ 1523 assertErrors(source, [
1351 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, 1524 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS,
1352 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); 1525 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]);
1353 verify([source]); 1526 verify([source]);
1354 } 1527 }
1355 1528
1356 void test_fieldInitializedByMultipleInitializers_multipleNames() { 1529 void test_fieldInitializedByMultipleInitializers_multipleNames() {
1357 Source source = addSource(EngineTestCase.createSource([ 1530 Source source = addSource(r'''
1358 "class A {", 1531 class A {
1359 " int x;", 1532 int x;
1360 " int y;", 1533 int y;
1361 " A() : x = 0, x = 1, y = 0, y = 1 {}", 1534 A() : x = 0, x = 1, y = 0, y = 1 {}
1362 "}"])); 1535 }''');
1363 resolve(source); 1536 resolve(source);
1364 assertErrors(source, [ 1537 assertErrors(source, [
1365 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, 1538 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS,
1366 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); 1539 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]);
1367 verify([source]); 1540 verify([source]);
1368 } 1541 }
1369 1542
1370 void test_fieldInitializedInParameterAndInitializer() { 1543 void test_fieldInitializedInParameterAndInitializer() {
1371 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " A(this.x) : x = 1 {}", "}"])); 1544 Source source = addSource(r'''
1545 class A {
1546 int x;
1547 A(this.x) : x = 1 {}
1548 }''');
1372 resolve(source); 1549 resolve(source);
1373 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AN D_INITIALIZER]); 1550 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AN D_INITIALIZER]);
1374 verify([source]); 1551 verify([source]);
1375 } 1552 }
1376 1553
1377 void test_fieldInitializerFactoryConstructor() { 1554 void test_fieldInitializerFactoryConstructor() {
1378 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " factory A(this.x) {}", "}"])); 1555 Source source = addSource(r'''
1556 class A {
1557 int x;
1558 factory A(this.x) {}
1559 }''');
1379 resolve(source); 1560 resolve(source);
1380 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRU CTOR]); 1561 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRU CTOR]);
1381 verify([source]); 1562 verify([source]);
1382 } 1563 }
1383 1564
1384 void test_fieldInitializerOutsideConstructor() { 1565 void test_fieldInitializerOutsideConstructor() {
1385 // TODO(brianwilkerson) Fix the duplicate error messages. 1566 // TODO(brianwilkerson) Fix the duplicate error messages.
1386 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " m(this.x) {}", "}"])); 1567 Source source = addSource(r'''
1568 class A {
1569 int x;
1570 m(this.x) {}
1571 }''');
1387 resolve(source); 1572 resolve(source);
1388 assertErrors(source, [ 1573 assertErrors(source, [
1389 ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 1574 ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR,
1390 CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); 1575 CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]);
1391 verify([source]); 1576 verify([source]);
1392 } 1577 }
1393 1578
1394 void test_fieldInitializerOutsideConstructor_defaultParameter() { 1579 void test_fieldInitializerOutsideConstructor_defaultParameter() {
1395 Source source = addSource(EngineTestCase.createSource(["class A {", " int x ;", " m([this.x]) {}", "}"])); 1580 Source source = addSource(r'''
1581 class A {
1582 int x;
1583 m([this.x]) {}
1584 }''');
1396 resolve(source); 1585 resolve(source);
1397 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRU CTOR]); 1586 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRU CTOR]);
1398 verify([source]); 1587 verify([source]);
1399 } 1588 }
1400 1589
1401 void test_fieldInitializerRedirectingConstructor_afterRedirection() { 1590 void test_fieldInitializerRedirectingConstructor_afterRedirection() {
1402 Source source = addSource(EngineTestCase.createSource([ 1591 Source source = addSource(r'''
1403 "class A {", 1592 class A {
1404 " int x;", 1593 int x;
1405 " A.named() {}", 1594 A.named() {}
1406 " A() : this.named(), x = 42;", 1595 A() : this.named(), x = 42;
1407 "}"])); 1596 }''');
1408 resolve(source); 1597 resolve(source);
1409 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CON STRUCTOR]); 1598 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CON STRUCTOR]);
1410 verify([source]); 1599 verify([source]);
1411 } 1600 }
1412 1601
1413 void test_fieldInitializerRedirectingConstructor_beforeRedirection() { 1602 void test_fieldInitializerRedirectingConstructor_beforeRedirection() {
1414 Source source = addSource(EngineTestCase.createSource([ 1603 Source source = addSource(r'''
1415 "class A {", 1604 class A {
1416 " int x;", 1605 int x;
1417 " A.named() {}", 1606 A.named() {}
1418 " A() : x = 42, this.named();", 1607 A() : x = 42, this.named();
1419 "}"])); 1608 }''');
1420 resolve(source); 1609 resolve(source);
1421 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CON STRUCTOR]); 1610 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CON STRUCTOR]);
1422 verify([source]); 1611 verify([source]);
1423 } 1612 }
1424 1613
1425 void test_fieldInitializingFormalRedirectingConstructor() { 1614 void test_fieldInitializingFormalRedirectingConstructor() {
1426 Source source = addSource(EngineTestCase.createSource([ 1615 Source source = addSource(r'''
1427 "class A {", 1616 class A {
1428 " int x;", 1617 int x;
1429 " A.named() {}", 1618 A.named() {}
1430 " A(this.x) : this.named();", 1619 A(this.x) : this.named();
1431 "}"])); 1620 }''');
1432 resolve(source); 1621 resolve(source);
1433 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CON STRUCTOR]); 1622 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CON STRUCTOR]);
1434 verify([source]); 1623 verify([source]);
1435 } 1624 }
1436 1625
1437 void test_finalInitializedMultipleTimes_initializers() { 1626 void test_finalInitializedMultipleTimes_initializers() {
1438 Source source = addSource(EngineTestCase.createSource(["class A {", " final x;", " A() : x = 0, x = 0 {}", "}"])); 1627 Source source = addSource(r'''
1628 class A {
1629 final x;
1630 A() : x = 0, x = 0 {}
1631 }''');
1439 resolve(source); 1632 resolve(source);
1440 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INI TIALIZERS]); 1633 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INI TIALIZERS]);
1441 verify([source]); 1634 verify([source]);
1442 } 1635 }
1443 1636
1444 /** 1637 /**
1445 * This test doesn't test the FINAL_INITIALIZED_MULTIPLE_TIMES code, but tests the 1638 * This test doesn't test the FINAL_INITIALIZED_MULTIPLE_TIMES code, but tests the
1446 * FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER code instead. It is provided here to show 1639 * FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER code instead. It is provided here to show
1447 * coverage over all of the permutations of initializers in constructor declar ations. 1640 * coverage over all of the permutations of initializers in constructor declar ations.
1448 * 1641 *
1449 * Note: FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER covers a subset of 1642 * Note: FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER covers a subset of
1450 * FINAL_INITIALIZED_MULTIPLE_TIMES, since it more specific, we use it instead of the broader code 1643 * FINAL_INITIALIZED_MULTIPLE_TIMES, since it more specific, we use it instead of the broader code
1451 */ 1644 */
1452 void test_finalInitializedMultipleTimes_initializingFormal_initializer() { 1645 void test_finalInitializedMultipleTimes_initializingFormal_initializer() {
1453 Source source = addSource(EngineTestCase.createSource(["class A {", " final x;", " A(this.x) : x = 0 {}", "}"])); 1646 Source source = addSource(r'''
1647 class A {
1648 final x;
1649 A(this.x) : x = 0 {}
1650 }''');
1454 resolve(source); 1651 resolve(source);
1455 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AN D_INITIALIZER]); 1652 assertErrors(source, [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AN D_INITIALIZER]);
1456 verify([source]); 1653 verify([source]);
1457 } 1654 }
1458 1655
1459 void test_finalInitializedMultipleTimes_initializingFormals() { 1656 void test_finalInitializedMultipleTimes_initializingFormals() {
1460 Source source = addSource(EngineTestCase.createSource(["class A {", " final x;", " A(this.x, this.x) {}", "}"])); 1657 Source source = addSource(r'''
1658 class A {
1659 final x;
1660 A(this.x, this.x) {}
1661 }''');
1461 resolve(source); 1662 resolve(source);
1462 assertErrors(source, [CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES] ); 1663 assertErrors(source, [CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES] );
1463 verify([source]); 1664 verify([source]);
1464 } 1665 }
1465 1666
1466 void test_finalNotInitialized_instanceField_const_static() { 1667 void test_finalNotInitialized_instanceField_const_static() {
1467 Source source = addSource(EngineTestCase.createSource(["class A {", " stati c const F;", "}"])); 1668 Source source = addSource(r'''
1669 class A {
1670 static const F;
1671 }''');
1468 resolve(source); 1672 resolve(source);
1469 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); 1673 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]);
1470 verify([source]); 1674 verify([source]);
1471 } 1675 }
1472 1676
1473 void test_finalNotInitialized_library_const() { 1677 void test_finalNotInitialized_library_const() {
1474 Source source = addSource(EngineTestCase.createSource(["const F;"])); 1678 Source source = addSource("const F;");
1475 resolve(source); 1679 resolve(source);
1476 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); 1680 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]);
1477 verify([source]); 1681 verify([source]);
1478 } 1682 }
1479 1683
1480 void test_finalNotInitialized_local_const() { 1684 void test_finalNotInitialized_local_const() {
1481 Source source = addSource(EngineTestCase.createSource(["f() {", " const int x;", "}"])); 1685 Source source = addSource(r'''
1686 f() {
1687 const int x;
1688 }''');
1482 resolve(source); 1689 resolve(source);
1483 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); 1690 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]);
1484 verify([source]); 1691 verify([source]);
1485 } 1692 }
1486 1693
1487 void test_fromEnvironment_bool_badArgs() { 1694 void test_fromEnvironment_bool_badArgs() {
1488 Source source = addSource(EngineTestCase.createSource([ 1695 Source source = addSource(r'''
1489 "var b1 = const bool.fromEnvironment(1);", 1696 var b1 = const bool.fromEnvironment(1);
1490 "var b2 = const bool.fromEnvironment('x', defaultValue: 1);"])); 1697 var b2 = const bool.fromEnvironment('x', defaultValue: 1);''');
1491 resolve(source); 1698 resolve(source);
1492 assertErrors(source, [ 1699 assertErrors(source, [
1493 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 1700 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
1494 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 1701 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
1495 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 1702 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
1496 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 1703 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
1497 verify([source]); 1704 verify([source]);
1498 } 1705 }
1499 1706
1500 void test_fromEnvironment_bool_badDefault_whenDefined() { 1707 void test_fromEnvironment_bool_badDefault_whenDefined() {
1501 // The type of the defaultValue needs to be correct even when the default va lue 1708 // The type of the defaultValue needs to be correct even when the default va lue
1502 // isn't used (because the variable is defined in the environment). 1709 // isn't used (because the variable is defined in the environment).
1503 analysisContext2.declaredVariables.define("x", "true"); 1710 analysisContext2.declaredVariables.define("x", "true");
1504 Source source = addSource(EngineTestCase.createSource(["var b = const bool.f romEnvironment('x', defaultValue: 1);"])); 1711 Source source = addSource("var b = const bool.fromEnvironment('x', defaultVa lue: 1);");
1505 resolve(source); 1712 resolve(source);
1506 assertErrors(source, [ 1713 assertErrors(source, [
1507 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 1714 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
1508 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 1715 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
1509 verify([source]); 1716 verify([source]);
1510 } 1717 }
1511 1718
1512 void test_getterAndMethodWithSameName() { 1719 void test_getterAndMethodWithSameName() {
1513 Source source = addSource(EngineTestCase.createSource(["class A {", " x(y) {}", " get x => 0;", "}"])); 1720 Source source = addSource(r'''
1721 class A {
1722 x(y) {}
1723 get x => 0;
1724 }''');
1514 resolve(source); 1725 resolve(source);
1515 assertErrors(source, [CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME] ); 1726 assertErrors(source, [CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME] );
1516 verify([source]); 1727 verify([source]);
1517 } 1728 }
1518 1729
1519 void test_implementsDeferredClass() { 1730 void test_implementsDeferredClass() {
1520 resolveWithAndWithoutExperimental(<String> [ 1731 resolveWithAndWithoutExperimental(<String> [
1521 EngineTestCase.createSource(["library lib1;", "class A {}"]), 1732 r'''
1522 EngineTestCase.createSource([ 1733 library lib1;
1523 "library root;", 1734 class A {}''',
1524 "import 'lib1.dart' deferred as a;", 1735 r'''
1525 "class B implements a.A {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IM PORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLAS S]); 1736 library root;
1737 import 'lib1.dart' deferred as a;
1738 class B implements a.A {}'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT _SUPPORTED], <ErrorCode> [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS]);
1526 } 1739 }
1527 1740
1528 void test_implementsDeferredClass_classTypeAlias() { 1741 void test_implementsDeferredClass_classTypeAlias() {
1529 resolveWithAndWithoutExperimental(<String> [ 1742 resolveWithAndWithoutExperimental(<String> [
1530 EngineTestCase.createSource(["library lib1;", "class A {}"]), 1743 r'''
1531 EngineTestCase.createSource([ 1744 library lib1;
1532 "library root;", 1745 class A {}''',
1533 "import 'lib1.dart' deferred as a;", 1746 r'''
1534 "class B {}", 1747 library root;
1535 "class M {}", 1748 import 'lib1.dart' deferred as a;
1536 "class C = B with M implements a.A;"])], <ErrorCode> [ParserErrorCode.DE FERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.IMPLEMENTS_DEFE RRED_CLASS]); 1749 class B {}
1750 class M {}
1751 class C = B with M implements a.A;'''], <ErrorCode> [ParserErrorCode.DEFERRED_IM PORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLAS S]);
1537 } 1752 }
1538 1753
1539 void test_implementsDisallowedClass_class_bool() { 1754 void test_implementsDisallowedClass_class_bool() {
1540 Source source = addSource(EngineTestCase.createSource(["class A implements b ool {}"])); 1755 Source source = addSource("class A implements bool {}");
1541 resolve(source); 1756 resolve(source);
1542 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1757 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1543 verify([source]); 1758 verify([source]);
1544 } 1759 }
1545 1760
1546 void test_implementsDisallowedClass_class_double() { 1761 void test_implementsDisallowedClass_class_double() {
1547 Source source = addSource(EngineTestCase.createSource(["class A implements d ouble {}"])); 1762 Source source = addSource("class A implements double {}");
1548 resolve(source); 1763 resolve(source);
1549 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1764 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1550 verify([source]); 1765 verify([source]);
1551 } 1766 }
1552 1767
1553 void test_implementsDisallowedClass_class_int() { 1768 void test_implementsDisallowedClass_class_int() {
1554 Source source = addSource(EngineTestCase.createSource(["class A implements i nt {}"])); 1769 Source source = addSource("class A implements int {}");
1555 resolve(source); 1770 resolve(source);
1556 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1771 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1557 verify([source]); 1772 verify([source]);
1558 } 1773 }
1559 1774
1560 void test_implementsDisallowedClass_class_Null() { 1775 void test_implementsDisallowedClass_class_Null() {
1561 Source source = addSource(EngineTestCase.createSource(["class A implements N ull {}"])); 1776 Source source = addSource("class A implements Null {}");
1562 resolve(source); 1777 resolve(source);
1563 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1778 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1564 verify([source]); 1779 verify([source]);
1565 } 1780 }
1566 1781
1567 void test_implementsDisallowedClass_class_num() { 1782 void test_implementsDisallowedClass_class_num() {
1568 Source source = addSource(EngineTestCase.createSource(["class A implements n um {}"])); 1783 Source source = addSource("class A implements num {}");
1569 resolve(source); 1784 resolve(source);
1570 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1785 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1571 verify([source]); 1786 verify([source]);
1572 } 1787 }
1573 1788
1574 void test_implementsDisallowedClass_class_String() { 1789 void test_implementsDisallowedClass_class_String() {
1575 Source source = addSource(EngineTestCase.createSource(["class A implements S tring {}"])); 1790 Source source = addSource("class A implements String {}");
1576 resolve(source); 1791 resolve(source);
1577 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1792 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1578 verify([source]); 1793 verify([source]);
1579 } 1794 }
1580 1795
1581 void test_implementsDisallowedClass_class_String_num() { 1796 void test_implementsDisallowedClass_class_String_num() {
1582 Source source = addSource(EngineTestCase.createSource(["class A implements S tring, num {}"])); 1797 Source source = addSource("class A implements String, num {}");
1583 resolve(source); 1798 resolve(source);
1584 assertErrors(source, [ 1799 assertErrors(source, [
1585 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 1800 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS,
1586 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1801 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1587 verify([source]); 1802 verify([source]);
1588 } 1803 }
1589 1804
1590 void test_implementsDisallowedClass_classTypeAlias_bool() { 1805 void test_implementsDisallowedClass_classTypeAlias_bool() {
1591 Source source = addSource(EngineTestCase.createSource([ 1806 Source source = addSource(r'''
1592 "class A {}", 1807 class A {}
1593 "class M {}", 1808 class M {}
1594 "class C = A with M implements bool;"])); 1809 class C = A with M implements bool;''');
1595 resolve(source); 1810 resolve(source);
1596 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1811 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1597 verify([source]); 1812 verify([source]);
1598 } 1813 }
1599 1814
1600 void test_implementsDisallowedClass_classTypeAlias_double() { 1815 void test_implementsDisallowedClass_classTypeAlias_double() {
1601 Source source = addSource(EngineTestCase.createSource([ 1816 Source source = addSource(r'''
1602 "class A {}", 1817 class A {}
1603 "class M {}", 1818 class M {}
1604 "class C = A with M implements double;"])); 1819 class C = A with M implements double;''');
1605 resolve(source); 1820 resolve(source);
1606 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1821 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1607 verify([source]); 1822 verify([source]);
1608 } 1823 }
1609 1824
1610 void test_implementsDisallowedClass_classTypeAlias_int() { 1825 void test_implementsDisallowedClass_classTypeAlias_int() {
1611 Source source = addSource(EngineTestCase.createSource([ 1826 Source source = addSource(r'''
1612 "class A {}", 1827 class A {}
1613 "class M {}", 1828 class M {}
1614 "class C = A with M implements int;"])); 1829 class C = A with M implements int;''');
1615 resolve(source); 1830 resolve(source);
1616 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1831 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1617 verify([source]); 1832 verify([source]);
1618 } 1833 }
1619 1834
1620 void test_implementsDisallowedClass_classTypeAlias_Null() { 1835 void test_implementsDisallowedClass_classTypeAlias_Null() {
1621 Source source = addSource(EngineTestCase.createSource([ 1836 Source source = addSource(r'''
1622 "class A {}", 1837 class A {}
1623 "class M {}", 1838 class M {}
1624 "class C = A with M implements Null;"])); 1839 class C = A with M implements Null;''');
1625 resolve(source); 1840 resolve(source);
1626 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1841 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1627 verify([source]); 1842 verify([source]);
1628 } 1843 }
1629 1844
1630 void test_implementsDisallowedClass_classTypeAlias_num() { 1845 void test_implementsDisallowedClass_classTypeAlias_num() {
1631 Source source = addSource(EngineTestCase.createSource([ 1846 Source source = addSource(r'''
1632 "class A {}", 1847 class A {}
1633 "class M {}", 1848 class M {}
1634 "class C = A with M implements num;"])); 1849 class C = A with M implements num;''');
1635 resolve(source); 1850 resolve(source);
1636 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1851 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1637 verify([source]); 1852 verify([source]);
1638 } 1853 }
1639 1854
1640 void test_implementsDisallowedClass_classTypeAlias_String() { 1855 void test_implementsDisallowedClass_classTypeAlias_String() {
1641 Source source = addSource(EngineTestCase.createSource([ 1856 Source source = addSource(r'''
1642 "class A {}", 1857 class A {}
1643 "class M {}", 1858 class M {}
1644 "class C = A with M implements String;"])); 1859 class C = A with M implements String;''');
1645 resolve(source); 1860 resolve(source);
1646 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1861 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1647 verify([source]); 1862 verify([source]);
1648 } 1863 }
1649 1864
1650 void test_implementsDisallowedClass_classTypeAlias_String_num() { 1865 void test_implementsDisallowedClass_classTypeAlias_String_num() {
1651 Source source = addSource(EngineTestCase.createSource([ 1866 Source source = addSource(r'''
1652 "class A {}", 1867 class A {}
1653 "class M {}", 1868 class M {}
1654 "class C = A with M implements String, num;"])); 1869 class C = A with M implements String, num;''');
1655 resolve(source); 1870 resolve(source);
1656 assertErrors(source, [ 1871 assertErrors(source, [
1657 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 1872 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS,
1658 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 1873 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
1659 verify([source]); 1874 verify([source]);
1660 } 1875 }
1661 1876
1662 void test_implementsDynamic() { 1877 void test_implementsDynamic() {
1663 Source source = addSource(EngineTestCase.createSource(["class A implements d ynamic {}"])); 1878 Source source = addSource("class A implements dynamic {}");
1664 resolve(source); 1879 resolve(source);
1665 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]); 1880 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]);
1666 verify([source]); 1881 verify([source]);
1667 } 1882 }
1668 1883
1669 void test_implementsEnum() { 1884 void test_implementsEnum() {
1670 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); 1885 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
1671 analysisOptions.enableEnum = true; 1886 analysisOptions.enableEnum = true;
1672 resetWithOptions(analysisOptions); 1887 resetWithOptions(analysisOptions);
1673 Source source = addSource(EngineTestCase.createSource(["enum E { ONE }", "cl ass A implements E {}"])); 1888 Source source = addSource(r'''
1889 enum E { ONE }
1890 class A implements E {}''');
1674 resolve(source); 1891 resolve(source);
1675 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_ENUM]); 1892 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_ENUM]);
1676 verify([source]); 1893 verify([source]);
1677 } 1894 }
1678 1895
1679 void test_implementsNonClass_class() { 1896 void test_implementsNonClass_class() {
1680 Source source = addSource(EngineTestCase.createSource(["int A;", "class B im plements A {}"])); 1897 Source source = addSource(r'''
1898 int A;
1899 class B implements A {}''');
1681 resolve(source); 1900 resolve(source);
1682 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); 1901 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]);
1683 verify([source]); 1902 verify([source]);
1684 } 1903 }
1685 1904
1686 void test_implementsNonClass_typeAlias() { 1905 void test_implementsNonClass_typeAlias() {
1687 Source source = addSource(EngineTestCase.createSource([ 1906 Source source = addSource(r'''
1688 "class A {}", 1907 class A {}
1689 "class M {}", 1908 class M {}
1690 "int B;", 1909 int B;
1691 "class C = A with M implements B;"])); 1910 class C = A with M implements B;''');
1692 resolve(source); 1911 resolve(source);
1693 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); 1912 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]);
1694 verify([source]); 1913 verify([source]);
1695 } 1914 }
1696 1915
1697 void test_implementsRepeated() { 1916 void test_implementsRepeated() {
1698 Source source = addSource(EngineTestCase.createSource(["class A {}", "class B implements A, A {}"])); 1917 Source source = addSource(r'''
1918 class A {}
1919 class B implements A, A {}''');
1699 resolve(source); 1920 resolve(source);
1700 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_REPEATED]); 1921 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_REPEATED]);
1701 verify([source]); 1922 verify([source]);
1702 } 1923 }
1703 1924
1704 void test_implementsRepeated_3times() { 1925 void test_implementsRepeated_3times() {
1705 Source source = addSource(EngineTestCase.createSource([ 1926 Source source = addSource(r'''
1706 "class A {} class C{}", 1927 class A {} class C{}
1707 "class B implements A, A, A, A {}"])); 1928 class B implements A, A, A, A {}''');
1708 resolve(source); 1929 resolve(source);
1709 assertErrors(source, [ 1930 assertErrors(source, [
1710 CompileTimeErrorCode.IMPLEMENTS_REPEATED, 1931 CompileTimeErrorCode.IMPLEMENTS_REPEATED,
1711 CompileTimeErrorCode.IMPLEMENTS_REPEATED, 1932 CompileTimeErrorCode.IMPLEMENTS_REPEATED,
1712 CompileTimeErrorCode.IMPLEMENTS_REPEATED]); 1933 CompileTimeErrorCode.IMPLEMENTS_REPEATED]);
1713 verify([source]); 1934 verify([source]);
1714 } 1935 }
1715 1936
1716 void test_implementsSuperClass() { 1937 void test_implementsSuperClass() {
1717 Source source = addSource(EngineTestCase.createSource(["class A {}", "class B extends A implements A {}"])); 1938 Source source = addSource(r'''
1939 class A {}
1940 class B extends A implements A {}''');
1718 resolve(source); 1941 resolve(source);
1719 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); 1942 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]);
1720 verify([source]); 1943 verify([source]);
1721 } 1944 }
1722 1945
1723 void test_implementsSuperClass_Object() { 1946 void test_implementsSuperClass_Object() {
1724 Source source = addSource(EngineTestCase.createSource(["class A implements O bject {}"])); 1947 Source source = addSource("class A implements Object {}");
1725 resolve(source); 1948 resolve(source);
1726 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); 1949 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]);
1727 verify([source]); 1950 verify([source]);
1728 } 1951 }
1729 1952
1730 void test_implicitThisReferenceInInitializer_field() { 1953 void test_implicitThisReferenceInInitializer_field() {
1731 Source source = addSource(EngineTestCase.createSource([ 1954 Source source = addSource(r'''
1732 "class A {", 1955 class A {
1733 " var v;", 1956 var v;
1734 " A() : v = f;", 1957 A() : v = f;
1735 " var f;", 1958 var f;
1736 "}"])); 1959 }''');
1737 resolve(source); 1960 resolve(source);
1738 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]); 1961 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]);
1739 verify([source]); 1962 verify([source]);
1740 } 1963 }
1741 1964
1742 void test_implicitThisReferenceInInitializer_field2() { 1965 void test_implicitThisReferenceInInitializer_field2() {
1743 Source source = addSource(EngineTestCase.createSource(["class A {", " final x = 0;", " final y = x;", "}"])); 1966 Source source = addSource(r'''
1967 class A {
1968 final x = 0;
1969 final y = x;
1970 }''');
1744 resolve(source); 1971 resolve(source);
1745 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]); 1972 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]);
1746 verify([source]); 1973 verify([source]);
1747 } 1974 }
1748 1975
1749 void test_implicitThisReferenceInInitializer_invocation() { 1976 void test_implicitThisReferenceInInitializer_invocation() {
1750 Source source = addSource(EngineTestCase.createSource([ 1977 Source source = addSource(r'''
1751 "class A {", 1978 class A {
1752 " var v;", 1979 var v;
1753 " A() : v = f();", 1980 A() : v = f();
1754 " f() {}", 1981 f() {}
1755 "}"])); 1982 }''');
1756 resolve(source); 1983 resolve(source);
1757 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]); 1984 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]);
1758 verify([source]); 1985 verify([source]);
1759 } 1986 }
1760 1987
1761 void test_implicitThisReferenceInInitializer_invocationInStatic() { 1988 void test_implicitThisReferenceInInitializer_invocationInStatic() {
1762 Source source = addSource(EngineTestCase.createSource(["class A {", " stati c var F = m();", " m() {}", "}"])); 1989 Source source = addSource(r'''
1990 class A {
1991 static var F = m();
1992 m() {}
1993 }''');
1763 resolve(source); 1994 resolve(source);
1764 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]); 1995 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]);
1765 verify([source]); 1996 verify([source]);
1766 } 1997 }
1767 1998
1768 void test_implicitThisReferenceInInitializer_redirectingConstructorInvocation( ) { 1999 void test_implicitThisReferenceInInitializer_redirectingConstructorInvocation( ) {
1769 Source source = addSource(EngineTestCase.createSource([ 2000 Source source = addSource(r'''
1770 "class A {", 2001 class A {
1771 " A(p) {}", 2002 A(p) {}
1772 " A.named() : this(f);", 2003 A.named() : this(f);
1773 " var f;", 2004 var f;
1774 "}"])); 2005 }''');
1775 resolve(source); 2006 resolve(source);
1776 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]); 2007 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]);
1777 verify([source]); 2008 verify([source]);
1778 } 2009 }
1779 2010
1780 void test_implicitThisReferenceInInitializer_superConstructorInvocation() { 2011 void test_implicitThisReferenceInInitializer_superConstructorInvocation() {
1781 Source source = addSource(EngineTestCase.createSource([ 2012 Source source = addSource(r'''
1782 "class A {", 2013 class A {
1783 " A(p) {}", 2014 A(p) {}
1784 "}", 2015 }
1785 "class B extends A {", 2016 class B extends A {
1786 " B() : super(f);", 2017 B() : super(f);
1787 " var f;", 2018 var f;
1788 "}"])); 2019 }''');
1789 resolve(source); 2020 resolve(source);
1790 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]); 2021 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA LIZER]);
1791 verify([source]); 2022 verify([source]);
1792 } 2023 }
1793 2024
1794 void test_importInternalLibrary() { 2025 void test_importInternalLibrary() {
1795 Source source = addSource(EngineTestCase.createSource(["import 'dart:_interc eptors';"])); 2026 Source source = addSource("import 'dart:_interceptors';");
1796 resolve(source); 2027 resolve(source);
1797 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while w e could prevent 2028 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while w e could prevent
1798 // the hint from being generated by testing the import directive for the err or, this is such a 2029 // the hint from being generated by testing the import directive for the err or, this is such a
1799 // minor corner case that we don't think we should add the additional comput ation time to figure 2030 // minor corner case that we don't think we should add the additional comput ation time to figure
1800 // out such cases. 2031 // out such cases.
1801 assertErrors(source, [ 2032 assertErrors(source, [
1802 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, 2033 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY,
1803 HintCode.UNUSED_IMPORT]); 2034 HintCode.UNUSED_IMPORT]);
1804 verify([source]); 2035 verify([source]);
1805 } 2036 }
1806 2037
1807 void test_importInternalLibrary_js_helper() { 2038 void test_importInternalLibrary_js_helper() {
1808 Source source = addSource(EngineTestCase.createSource(["import 'dart:_js_hel per';"])); 2039 Source source = addSource("import 'dart:_js_helper';");
1809 resolve(source); 2040 resolve(source);
1810 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while w e could prevent 2041 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while w e could prevent
1811 // the hint from being generated by testing the import directive for the err or, this is such a 2042 // the hint from being generated by testing the import directive for the err or, this is such a
1812 // minor corner case that we don't think we should add the additional comput ation time to figure 2043 // minor corner case that we don't think we should add the additional comput ation time to figure
1813 // out such cases. 2044 // out such cases.
1814 assertErrors(source, [ 2045 assertErrors(source, [
1815 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, 2046 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY,
1816 HintCode.UNUSED_IMPORT]); 2047 HintCode.UNUSED_IMPORT]);
1817 verify([source]); 2048 verify([source]);
1818 } 2049 }
1819 2050
1820 void test_importOfNonLibrary() { 2051 void test_importOfNonLibrary() {
1821 Source source = addSource(EngineTestCase.createSource(["library lib;", "impo rt 'part.dart';", "A a;"])); 2052 Source source = addSource(r'''
1822 addNamedSource("/part.dart", EngineTestCase.createSource(["part of lib;", "c lass A{}"])); 2053 library lib;
2054 import 'part.dart';
2055 A a;''');
2056 addNamedSource("/part.dart", r'''
2057 part of lib;
2058 class A{}''');
1823 resolve(source); 2059 resolve(source);
1824 assertErrors(source, [CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); 2060 assertErrors(source, [CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]);
1825 verify([source]); 2061 verify([source]);
1826 } 2062 }
1827 2063
1828 void test_inconsistentCaseExpressionTypes() { 2064 void test_inconsistentCaseExpressionTypes() {
1829 Source source = addSource(EngineTestCase.createSource([ 2065 Source source = addSource(r'''
1830 "f(var p) {", 2066 f(var p) {
1831 " switch (p) {", 2067 switch (p) {
1832 " case 1:", 2068 case 1:
1833 " break;", 2069 break;
1834 " case 'a':", 2070 case 'a':
1835 " break;", 2071 break;
1836 " }", 2072 }
1837 "}"])); 2073 }''');
1838 resolve(source); 2074 resolve(source);
1839 assertErrors(source, [CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPE S]); 2075 assertErrors(source, [CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPE S]);
1840 verify([source]); 2076 verify([source]);
1841 } 2077 }
1842 2078
1843 void test_inconsistentCaseExpressionTypes_dynamic() { 2079 void test_inconsistentCaseExpressionTypes_dynamic() {
1844 // Even though A.S and S have a static type of "dynamic", we should see 2080 // Even though A.S and S have a static type of "dynamic", we should see
1845 // that they fail to match 3, because they are constant strings. 2081 // that they fail to match 3, because they are constant strings.
1846 Source source = addSource(EngineTestCase.createSource([ 2082 Source source = addSource(r'''
1847 "class A {", 2083 class A {
1848 " static const S = 'A.S';", 2084 static const S = 'A.S';
1849 "}", 2085 }
1850 "", 2086
1851 "const S = 'S';", 2087 const S = 'S';
1852 "", 2088
1853 "foo(var p) {", 2089 foo(var p) {
1854 " switch (p) {", 2090 switch (p) {
1855 " case 3:", 2091 case 3:
1856 " break;", 2092 break;
1857 " case S:", 2093 case S:
1858 " break;", 2094 break;
1859 " case A.S:", 2095 case A.S:
1860 " break;", 2096 break;
1861 " }", 2097 }
1862 "}"])); 2098 }''');
1863 resolve(source); 2099 resolve(source);
1864 assertErrors(source, [ 2100 assertErrors(source, [
1865 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, 2101 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES,
1866 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]); 2102 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]);
1867 verify([source]); 2103 verify([source]);
1868 } 2104 }
1869 2105
1870 void test_inconsistentCaseExpressionTypes_repeated() { 2106 void test_inconsistentCaseExpressionTypes_repeated() {
1871 Source source = addSource(EngineTestCase.createSource([ 2107 Source source = addSource(r'''
1872 "f(var p) {", 2108 f(var p) {
1873 " switch (p) {", 2109 switch (p) {
1874 " case 1:", 2110 case 1:
1875 " break;", 2111 break;
1876 " case 'a':", 2112 case 'a':
1877 " break;", 2113 break;
1878 " case 'b':", 2114 case 'b':
1879 " break;", 2115 break;
1880 " }", 2116 }
1881 "}"])); 2117 }''');
1882 resolve(source); 2118 resolve(source);
1883 assertErrors(source, [ 2119 assertErrors(source, [
1884 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, 2120 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES,
1885 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]); 2121 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]);
1886 verify([source]); 2122 verify([source]);
1887 } 2123 }
1888 2124
1889 void test_initializerForNonExistent_const() { 2125 void test_initializerForNonExistent_const() {
1890 // Check that the absence of a matching field doesn't cause a 2126 // Check that the absence of a matching field doesn't cause a
1891 // crash during constant evaluation. 2127 // crash during constant evaluation.
1892 Source source = addSource(EngineTestCase.createSource([ 2128 Source source = addSource(r'''
1893 "class A {", 2129 class A {
1894 " const A() : x = 'foo';", 2130 const A() : x = 'foo';
1895 "}", 2131 }
1896 "A a = const A();"])); 2132 A a = const A();''');
1897 resolve(source); 2133 resolve(source);
1898 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIEL D]); 2134 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIEL D]);
1899 } 2135 }
1900 2136
1901 void test_initializerForNonExistent_initializer() { 2137 void test_initializerForNonExistent_initializer() {
1902 Source source = addSource(EngineTestCase.createSource(["class A {", " A() : x = 0 {}", "}"])); 2138 Source source = addSource(r'''
2139 class A {
2140 A() : x = 0 {}
2141 }''');
1903 resolve(source); 2142 resolve(source);
1904 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIEL D]); 2143 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIEL D]);
1905 } 2144 }
1906 2145
1907 void test_initializerForStaticField() { 2146 void test_initializerForStaticField() {
1908 Source source = addSource(EngineTestCase.createSource(["class A {", " stati c int x;", " A() : x = 0 {}", "}"])); 2147 Source source = addSource(r'''
2148 class A {
2149 static int x;
2150 A() : x = 0 {}
2151 }''');
1909 resolve(source); 2152 resolve(source);
1910 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD]); 2153 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD]);
1911 verify([source]); 2154 verify([source]);
1912 } 2155 }
1913 2156
1914 void test_initializingFormalForNonExistentField() { 2157 void test_initializingFormalForNonExistentField() {
1915 Source source = addSource(EngineTestCase.createSource(["class A {", " A(thi s.x) {}", "}"])); 2158 Source source = addSource(r'''
2159 class A {
2160 A(this.x) {}
2161 }''');
1916 resolve(source); 2162 resolve(source);
1917 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST ENT_FIELD]); 2163 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST ENT_FIELD]);
1918 verify([source]); 2164 verify([source]);
1919 } 2165 }
1920 2166
1921 void test_initializingFormalForNonExistentField_notInEnclosingClass() { 2167 void test_initializingFormalForNonExistentField_notInEnclosingClass() {
1922 Source source = addSource(EngineTestCase.createSource([ 2168 Source source = addSource(r'''
1923 "class A {", 2169 class A {
1924 "int x;", 2170 int x;
1925 "}", 2171 }
1926 "class B extends A {", 2172 class B extends A {
1927 " B(this.x) {}", 2173 B(this.x) {}
1928 "}"])); 2174 }''');
1929 resolve(source); 2175 resolve(source);
1930 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST ENT_FIELD]); 2176 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST ENT_FIELD]);
1931 verify([source]); 2177 verify([source]);
1932 } 2178 }
1933 2179
1934 void test_initializingFormalForNonExistentField_optional() { 2180 void test_initializingFormalForNonExistentField_optional() {
1935 Source source = addSource(EngineTestCase.createSource(["class A {", " A([th is.x]) {}", "}"])); 2181 Source source = addSource(r'''
2182 class A {
2183 A([this.x]) {}
2184 }''');
1936 resolve(source); 2185 resolve(source);
1937 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST ENT_FIELD]); 2186 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST ENT_FIELD]);
1938 verify([source]); 2187 verify([source]);
1939 } 2188 }
1940 2189
1941 void test_initializingFormalForNonExistentField_synthetic() { 2190 void test_initializingFormalForNonExistentField_synthetic() {
1942 Source source = addSource(EngineTestCase.createSource(["class A {", " int g et x => 1;", " A(this.x) {}", "}"])); 2191 Source source = addSource(r'''
2192 class A {
2193 int get x => 1;
2194 A(this.x) {}
2195 }''');
1943 resolve(source); 2196 resolve(source);
1944 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST ENT_FIELD]); 2197 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXIST ENT_FIELD]);
1945 verify([source]); 2198 verify([source]);
1946 } 2199 }
1947 2200
1948 void test_initializingFormalForStaticField() { 2201 void test_initializingFormalForStaticField() {
1949 Source source = addSource(EngineTestCase.createSource(["class A {", " stati c int x;", " A([this.x]) {}", "}"])); 2202 Source source = addSource(r'''
2203 class A {
2204 static int x;
2205 A([this.x]) {}
2206 }''');
1950 resolve(source); 2207 resolve(source);
1951 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FI ELD]); 2208 assertErrors(source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FI ELD]);
1952 verify([source]); 2209 verify([source]);
1953 } 2210 }
1954 2211
1955 void test_instanceMemberAccessFromFactory_named() { 2212 void test_instanceMemberAccessFromFactory_named() {
1956 Source source = addSource(EngineTestCase.createSource([ 2213 Source source = addSource(r'''
1957 "class A {", 2214 class A {
1958 " m() {}", 2215 m() {}
1959 " A();", 2216 A();
1960 " factory A.make() {", 2217 factory A.make() {
1961 " m();", 2218 m();
1962 " return new A();", 2219 return new A();
1963 " }", 2220 }
1964 "}"])); 2221 }''');
1965 resolve(source); 2222 resolve(source);
1966 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTO RY]); 2223 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTO RY]);
1967 verify([source]); 2224 verify([source]);
1968 } 2225 }
1969 2226
1970 void test_instanceMemberAccessFromFactory_unnamed() { 2227 void test_instanceMemberAccessFromFactory_unnamed() {
1971 Source source = addSource(EngineTestCase.createSource([ 2228 Source source = addSource(r'''
1972 "class A {", 2229 class A {
1973 " m() {}", 2230 m() {}
1974 " A._();", 2231 A._();
1975 " factory A() {", 2232 factory A() {
1976 " m();", 2233 m();
1977 " return new A._();", 2234 return new A._();
1978 " }", 2235 }
1979 "}"])); 2236 }''');
1980 resolve(source); 2237 resolve(source);
1981 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTO RY]); 2238 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTO RY]);
1982 verify([source]); 2239 verify([source]);
1983 } 2240 }
1984 2241
1985 void test_instanceMemberAccessFromStatic_field() { 2242 void test_instanceMemberAccessFromStatic_field() {
1986 Source source = addSource(EngineTestCase.createSource([ 2243 Source source = addSource(r'''
1987 "class A {", 2244 class A {
1988 " int f;", 2245 int f;
1989 " static foo() {", 2246 static foo() {
1990 " f;", 2247 f;
1991 " }", 2248 }
1992 "}"])); 2249 }''');
1993 resolve(source); 2250 resolve(source);
1994 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATI C]); 2251 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATI C]);
1995 verify([source]); 2252 verify([source]);
1996 } 2253 }
1997 2254
1998 void test_instanceMemberAccessFromStatic_getter() { 2255 void test_instanceMemberAccessFromStatic_getter() {
1999 Source source = addSource(EngineTestCase.createSource([ 2256 Source source = addSource(r'''
2000 "class A {", 2257 class A {
2001 " get g => null;", 2258 get g => null;
2002 " static foo() {", 2259 static foo() {
2003 " g;", 2260 g;
2004 " }", 2261 }
2005 "}"])); 2262 }''');
2006 resolve(source); 2263 resolve(source);
2007 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATI C]); 2264 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATI C]);
2008 verify([source]); 2265 verify([source]);
2009 } 2266 }
2010 2267
2011 void test_instanceMemberAccessFromStatic_method() { 2268 void test_instanceMemberAccessFromStatic_method() {
2012 Source source = addSource(EngineTestCase.createSource([ 2269 Source source = addSource(r'''
2013 "class A {", 2270 class A {
2014 " m() {}", 2271 m() {}
2015 " static foo() {", 2272 static foo() {
2016 " m();", 2273 m();
2017 " }", 2274 }
2018 "}"])); 2275 }''');
2019 resolve(source); 2276 resolve(source);
2020 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATI C]); 2277 assertErrors(source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATI C]);
2021 verify([source]); 2278 verify([source]);
2022 } 2279 }
2023 2280
2024 void test_instantiateEnum_const() { 2281 void test_instantiateEnum_const() {
2025 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); 2282 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
2026 analysisOptions.enableEnum = true; 2283 analysisOptions.enableEnum = true;
2027 resetWithOptions(analysisOptions); 2284 resetWithOptions(analysisOptions);
2028 Source source = addSource(EngineTestCase.createSource([ 2285 Source source = addSource(r'''
2029 "enum E { ONE }", 2286 enum E { ONE }
2030 "E e(String name) {", 2287 E e(String name) {
2031 " return const E();", 2288 return const E();
2032 "}"])); 2289 }''');
2033 resolve(source); 2290 resolve(source);
2034 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); 2291 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]);
2035 verify([source]); 2292 verify([source]);
2036 } 2293 }
2037 2294
2038 void test_instantiateEnum_new() { 2295 void test_instantiateEnum_new() {
2039 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); 2296 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
2040 analysisOptions.enableEnum = true; 2297 analysisOptions.enableEnum = true;
2041 resetWithOptions(analysisOptions); 2298 resetWithOptions(analysisOptions);
2042 Source source = addSource(EngineTestCase.createSource([ 2299 Source source = addSource(r'''
2043 "enum E { ONE }", 2300 enum E { ONE }
2044 "E e(String name) {", 2301 E e(String name) {
2045 " return new E();", 2302 return new E();
2046 "}"])); 2303 }''');
2047 resolve(source); 2304 resolve(source);
2048 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); 2305 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]);
2049 verify([source]); 2306 verify([source]);
2050 } 2307 }
2051 2308
2052 void test_invalidAnnotation_getter() { 2309 void test_invalidAnnotation_getter() {
2053 Source source = addSource(EngineTestCase.createSource(["get V => 0;", "@V", "main() {", "}"])); 2310 Source source = addSource(r'''
2311 get V => 0;
2312 @V
2313 main() {
2314 }''');
2054 resolve(source); 2315 resolve(source);
2055 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2316 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2056 verify([source]); 2317 verify([source]);
2057 } 2318 }
2058 2319
2059 void test_invalidAnnotation_importWithPrefix_getter() { 2320 void test_invalidAnnotation_importWithPrefix_getter() {
2060 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "ge t V => 0;"])); 2321 addNamedSource("/lib.dart", r'''
2061 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "@p.V", "main() {", "}"])); 2322 library lib;
2323 get V => 0;''');
2324 Source source = addSource(r'''
2325 import 'lib.dart' as p;
2326 @p.V
2327 main() {
2328 }''');
2062 resolve(source); 2329 resolve(source);
2063 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2330 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2064 verify([source]); 2331 verify([source]);
2065 } 2332 }
2066 2333
2067 void test_invalidAnnotation_importWithPrefix_notConstantVariable() { 2334 void test_invalidAnnotation_importWithPrefix_notConstantVariable() {
2068 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "fi nal V = 0;"])); 2335 addNamedSource("/lib.dart", r'''
2069 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "@p.V", "main() {", "}"])); 2336 library lib;
2337 final V = 0;''');
2338 Source source = addSource(r'''
2339 import 'lib.dart' as p;
2340 @p.V
2341 main() {
2342 }''');
2070 resolve(source); 2343 resolve(source);
2071 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2344 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2072 verify([source]); 2345 verify([source]);
2073 } 2346 }
2074 2347
2075 void test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocatio n() { 2348 void test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocatio n() {
2076 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "ty pedef V();"])); 2349 addNamedSource("/lib.dart", r'''
2077 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "@p.V", "main() {", "}"])); 2350 library lib;
2351 typedef V();''');
2352 Source source = addSource(r'''
2353 import 'lib.dart' as p;
2354 @p.V
2355 main() {
2356 }''');
2078 resolve(source); 2357 resolve(source);
2079 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2358 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2080 verify([source]); 2359 verify([source]);
2081 } 2360 }
2082 2361
2083 void test_invalidAnnotation_notConstantVariable() { 2362 void test_invalidAnnotation_notConstantVariable() {
2084 Source source = addSource(EngineTestCase.createSource(["final V = 0;", "@V", "main() {", "}"])); 2363 Source source = addSource(r'''
2364 final V = 0;
2365 @V
2366 main() {
2367 }''');
2085 resolve(source); 2368 resolve(source);
2086 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2369 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2087 verify([source]); 2370 verify([source]);
2088 } 2371 }
2089 2372
2090 void test_invalidAnnotation_notVariableOrConstructorInvocation() { 2373 void test_invalidAnnotation_notVariableOrConstructorInvocation() {
2091 Source source = addSource(EngineTestCase.createSource(["typedef V();", "@V", "main() {", "}"])); 2374 Source source = addSource(r'''
2375 typedef V();
2376 @V
2377 main() {
2378 }''');
2092 resolve(source); 2379 resolve(source);
2093 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2380 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2094 verify([source]); 2381 verify([source]);
2095 } 2382 }
2096 2383
2097 void test_invalidAnnotation_staticMethodReference() { 2384 void test_invalidAnnotation_staticMethodReference() {
2098 Source source = addSource(EngineTestCase.createSource([ 2385 Source source = addSource(r'''
2099 "class A {", 2386 class A {
2100 " static f() {}", 2387 static f() {}
2101 "}", 2388 }
2102 "@A.f", 2389 @A.f
2103 "main() {", 2390 main() {
2104 "}"])); 2391 }''');
2105 resolve(source); 2392 resolve(source);
2106 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2393 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2107 verify([source]); 2394 verify([source]);
2108 } 2395 }
2109 2396
2110 void test_invalidAnnotation_unresolved_identifier() { 2397 void test_invalidAnnotation_unresolved_identifier() {
2111 Source source = addSource(EngineTestCase.createSource(["@unresolved", "main( ) {", "}"])); 2398 Source source = addSource(r'''
2399 @unresolved
2400 main() {
2401 }''');
2112 resolve(source); 2402 resolve(source);
2113 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2403 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2114 } 2404 }
2115 2405
2116 void test_invalidAnnotation_unresolved_invocation() { 2406 void test_invalidAnnotation_unresolved_invocation() {
2117 Source source = addSource(EngineTestCase.createSource(["@Unresolved()", "mai n() {", "}"])); 2407 Source source = addSource(r'''
2408 @Unresolved()
2409 main() {
2410 }''');
2118 resolve(source); 2411 resolve(source);
2119 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2412 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2120 } 2413 }
2121 2414
2122 void test_invalidAnnotation_unresolved_prefixedIdentifier() { 2415 void test_invalidAnnotation_unresolved_prefixedIdentifier() {
2123 Source source = addSource(EngineTestCase.createSource([ 2416 Source source = addSource(r'''
2124 "import 'dart:math' as p;", 2417 import 'dart:math' as p;
2125 "@p.unresolved", 2418 @p.unresolved
2126 "main() {", 2419 main() {
2127 "}"])); 2420 }''');
2128 resolve(source); 2421 resolve(source);
2129 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2422 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2130 } 2423 }
2131 2424
2132 void test_invalidAnnotation_useLibraryScope() { 2425 void test_invalidAnnotation_useLibraryScope() {
2133 Source source = addSource(EngineTestCase.createSource(["@foo", "class A {", " static const foo = null;", "}"])); 2426 Source source = addSource(r'''
2427 @foo
2428 class A {
2429 static const foo = null;
2430 }''');
2134 resolve(source); 2431 resolve(source);
2135 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2432 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2136 } 2433 }
2137 2434
2138 void test_invalidAnnotationFromDeferredLibrary() { 2435 void test_invalidAnnotationFromDeferredLibrary() {
2139 // See test_invalidAnnotation_notConstantVariable 2436 // See test_invalidAnnotation_notConstantVariable
2140 resolveWithAndWithoutExperimental(<String> [ 2437 resolveWithAndWithoutExperimental(<String> [
2141 EngineTestCase.createSource([ 2438 r'''
2142 "library lib1;", 2439 library lib1;
2143 "class V { const V(); }", 2440 class V { const V(); }
2144 "const v = const V();"]), 2441 const v = const V();''',
2145 EngineTestCase.createSource([ 2442 r'''
2146 "library root;", 2443 library root;
2147 "import 'lib1.dart' deferred as a;", 2444 import 'lib1.dart' deferred as a;
2148 "@a.v main () {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_ SUPPORTED], <ErrorCode> [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_L IBRARY]); 2445 @a.v main () {}'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED ], <ErrorCode> [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY]);
2149 } 2446 }
2150 2447
2151 void test_invalidAnnotationFromDeferredLibrary_constructor() { 2448 void test_invalidAnnotationFromDeferredLibrary_constructor() {
2152 // See test_invalidAnnotation_notConstantVariable 2449 // See test_invalidAnnotation_notConstantVariable
2153 resolveWithAndWithoutExperimental(<String> [ 2450 resolveWithAndWithoutExperimental(<String> [
2154 EngineTestCase.createSource(["library lib1;", "class C { const C(); }"]) , 2451 r'''
2155 EngineTestCase.createSource([ 2452 library lib1;
2156 "library root;", 2453 class C { const C(); }''',
2157 "import 'lib1.dart' deferred as a;", 2454 r'''
2158 "@a.C() main () {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NO T_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED _LIBRARY]); 2455 library root;
2456 import 'lib1.dart' deferred as a;
2457 @a.C() main () {}'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORT ED], <ErrorCode> [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY] );
2159 } 2458 }
2160 2459
2161 void test_invalidAnnotationFromDeferredLibrary_namedConstructor() { 2460 void test_invalidAnnotationFromDeferredLibrary_namedConstructor() {
2162 // See test_invalidAnnotation_notConstantVariable 2461 // See test_invalidAnnotation_notConstantVariable
2163 resolveWithAndWithoutExperimental(<String> [ 2462 resolveWithAndWithoutExperimental(<String> [
2164 EngineTestCase.createSource(["library lib1;", "class C { const C.name(); }"]), 2463 r'''
2165 EngineTestCase.createSource([ 2464 library lib1;
2166 "library root;", 2465 class C { const C.name(); }''',
2167 "import 'lib1.dart' deferred as a;", 2466 r'''
2168 "@a.C.name() main () {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPOR TS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEF ERRED_LIBRARY]); 2467 library root;
2468 import 'lib1.dart' deferred as a;
2469 @a.C.name() main () {}'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SU PPORTED], <ErrorCode> [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIB RARY]);
2169 } 2470 }
2170 2471
2171 void test_invalidConstructorName_notEnclosingClassName_defined() { 2472 void test_invalidConstructorName_notEnclosingClassName_defined() {
2172 Source source = addSource(EngineTestCase.createSource(["class A {", " B() : super();", "}", "class B {}"])); 2473 Source source = addSource(r'''
2474 class A {
2475 B() : super();
2476 }
2477 class B {}''');
2173 resolve(source); 2478 resolve(source);
2174 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); 2479 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]);
2175 // no verify() call, "B" is not resolved 2480 // no verify() call, "B" is not resolved
2176 } 2481 }
2177 2482
2178 void test_invalidConstructorName_notEnclosingClassName_undefined() { 2483 void test_invalidConstructorName_notEnclosingClassName_undefined() {
2179 Source source = addSource(EngineTestCase.createSource(["class A {", " B() : super();", "}"])); 2484 Source source = addSource(r'''
2485 class A {
2486 B() : super();
2487 }''');
2180 resolve(source); 2488 resolve(source);
2181 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); 2489 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]);
2182 // no verify() call, "B" is not resolved 2490 // no verify() call, "B" is not resolved
2183 } 2491 }
2184 2492
2185 void test_invalidFactoryNameNotAClass_notClassName() { 2493 void test_invalidFactoryNameNotAClass_notClassName() {
2186 Source source = addSource(EngineTestCase.createSource(["int B;", "class A {" , " factory B() {}", "}"])); 2494 Source source = addSource(r'''
2495 int B;
2496 class A {
2497 factory B() {}
2498 }''');
2187 resolve(source); 2499 resolve(source);
2188 assertErrors(source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS] ); 2500 assertErrors(source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS] );
2189 verify([source]); 2501 verify([source]);
2190 } 2502 }
2191 2503
2192 void test_invalidFactoryNameNotAClass_notEnclosingClassName() { 2504 void test_invalidFactoryNameNotAClass_notEnclosingClassName() {
2193 Source source = addSource(EngineTestCase.createSource(["class A {", " facto ry B() {}", "}"])); 2505 Source source = addSource(r'''
2506 class A {
2507 factory B() {}
2508 }''');
2194 resolve(source); 2509 resolve(source);
2195 assertErrors(source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS] ); 2510 assertErrors(source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS] );
2196 // no verify() call, "B" is not resolved 2511 // no verify() call, "B" is not resolved
2197 } 2512 }
2198 2513
2199 void test_invalidModifierOnConstructor_async() { 2514 void test_invalidModifierOnConstructor_async() {
2200 resetWithAsync(); 2515 resetWithAsync();
2201 Source source = addSource(EngineTestCase.createSource(["class A {", " A() a sync {}", "}"])); 2516 Source source = addSource(r'''
2517 class A {
2518 A() async {}
2519 }''');
2202 resolve(source); 2520 resolve(source);
2203 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]) ; 2521 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]) ;
2204 verify([source]); 2522 verify([source]);
2205 } 2523 }
2206 2524
2207 void test_invalidModifierOnConstructor_asyncStar() { 2525 void test_invalidModifierOnConstructor_asyncStar() {
2208 resetWithAsync(); 2526 resetWithAsync();
2209 Source source = addSource(EngineTestCase.createSource(["class A {", " A() a sync* {}", "}"])); 2527 Source source = addSource(r'''
2528 class A {
2529 A() async* {}
2530 }''');
2210 resolve(source); 2531 resolve(source);
2211 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]) ; 2532 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]) ;
2212 verify([source]); 2533 verify([source]);
2213 } 2534 }
2214 2535
2215 void test_invalidModifierOnConstructor_syncStar() { 2536 void test_invalidModifierOnConstructor_syncStar() {
2216 resetWithAsync(); 2537 resetWithAsync();
2217 Source source = addSource(EngineTestCase.createSource(["class A {", " A() s ync* {}", "}"])); 2538 Source source = addSource(r'''
2539 class A {
2540 A() sync* {}
2541 }''');
2218 resolve(source); 2542 resolve(source);
2219 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]) ; 2543 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]) ;
2220 verify([source]); 2544 verify([source]);
2221 } 2545 }
2222 2546
2223 void test_invalidModifierOnSetter_member_async() { 2547 void test_invalidModifierOnSetter_member_async() {
2224 resetWithAsync(); 2548 resetWithAsync();
2225 Source source = addSource(EngineTestCase.createSource(["class A {", " set x (v) async {}", "}"])); 2549 Source source = addSource(r'''
2550 class A {
2551 set x(v) async {}
2552 }''');
2226 resolve(source); 2553 resolve(source);
2227 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2554 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2228 verify([source]); 2555 verify([source]);
2229 } 2556 }
2230 2557
2231 void test_invalidModifierOnSetter_member_asyncStar() { 2558 void test_invalidModifierOnSetter_member_asyncStar() {
2232 resetWithAsync(); 2559 resetWithAsync();
2233 Source source = addSource(EngineTestCase.createSource(["class A {", " set x (v) async* {}", "}"])); 2560 Source source = addSource(r'''
2561 class A {
2562 set x(v) async* {}
2563 }''');
2234 resolve(source); 2564 resolve(source);
2235 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2565 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2236 verify([source]); 2566 verify([source]);
2237 } 2567 }
2238 2568
2239 void test_invalidModifierOnSetter_member_syncStar() { 2569 void test_invalidModifierOnSetter_member_syncStar() {
2240 resetWithAsync(); 2570 resetWithAsync();
2241 Source source = addSource(EngineTestCase.createSource(["class A {", " set x (v) sync* {}", "}"])); 2571 Source source = addSource(r'''
2572 class A {
2573 set x(v) sync* {}
2574 }''');
2242 resolve(source); 2575 resolve(source);
2243 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2576 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2244 verify([source]); 2577 verify([source]);
2245 } 2578 }
2246 2579
2247 void test_invalidModifierOnSetter_topLevel_async() { 2580 void test_invalidModifierOnSetter_topLevel_async() {
2248 resetWithAsync(); 2581 resetWithAsync();
2249 Source source = addSource(EngineTestCase.createSource(["set x(v) async {}"]) ); 2582 Source source = addSource("set x(v) async {}");
2250 resolve(source); 2583 resolve(source);
2251 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2584 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2252 verify([source]); 2585 verify([source]);
2253 } 2586 }
2254 2587
2255 void test_invalidModifierOnSetter_topLevel_asyncStar() { 2588 void test_invalidModifierOnSetter_topLevel_asyncStar() {
2256 resetWithAsync(); 2589 resetWithAsync();
2257 Source source = addSource(EngineTestCase.createSource(["set x(v) async* {}"] )); 2590 Source source = addSource("set x(v) async* {}");
2258 resolve(source); 2591 resolve(source);
2259 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2592 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2260 verify([source]); 2593 verify([source]);
2261 } 2594 }
2262 2595
2263 void test_invalidModifierOnSetter_topLevel_syncStar() { 2596 void test_invalidModifierOnSetter_topLevel_syncStar() {
2264 resetWithAsync(); 2597 resetWithAsync();
2265 Source source = addSource(EngineTestCase.createSource(["set x(v) sync* {}"]) ); 2598 Source source = addSource("set x(v) sync* {}");
2266 resolve(source); 2599 resolve(source);
2267 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2600 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2268 verify([source]); 2601 verify([source]);
2269 } 2602 }
2270 2603
2271 void test_invalidReferenceToThis_factoryConstructor() { 2604 void test_invalidReferenceToThis_factoryConstructor() {
2272 Source source = addSource(EngineTestCase.createSource(["class A {", " facto ry A() { return this; }", "}"])); 2605 Source source = addSource(r'''
2606 class A {
2607 factory A() { return this; }
2608 }''');
2273 resolve(source); 2609 resolve(source);
2274 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 2610 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
2275 verify([source]); 2611 verify([source]);
2276 } 2612 }
2277 2613
2278 void test_invalidReferenceToThis_instanceVariableInitializer_inConstructor() { 2614 void test_invalidReferenceToThis_instanceVariableInitializer_inConstructor() {
2279 Source source = addSource(EngineTestCase.createSource(["class A {", " var f ;", " A() : f = this;", "}"])); 2615 Source source = addSource(r'''
2616 class A {
2617 var f;
2618 A() : f = this;
2619 }''');
2280 resolve(source); 2620 resolve(source);
2281 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 2621 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
2282 verify([source]); 2622 verify([source]);
2283 } 2623 }
2284 2624
2285 void test_invalidReferenceToThis_instanceVariableInitializer_inDeclaration() { 2625 void test_invalidReferenceToThis_instanceVariableInitializer_inDeclaration() {
2286 Source source = addSource(EngineTestCase.createSource(["class A {", " var f = this;", "}"])); 2626 Source source = addSource(r'''
2627 class A {
2628 var f = this;
2629 }''');
2287 resolve(source); 2630 resolve(source);
2288 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 2631 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
2289 verify([source]); 2632 verify([source]);
2290 } 2633 }
2291 2634
2292 void test_invalidReferenceToThis_staticMethod() { 2635 void test_invalidReferenceToThis_staticMethod() {
2293 Source source = addSource(EngineTestCase.createSource(["class A {", " stati c m() { return this; }", "}"])); 2636 Source source = addSource(r'''
2637 class A {
2638 static m() { return this; }
2639 }''');
2294 resolve(source); 2640 resolve(source);
2295 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 2641 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
2296 verify([source]); 2642 verify([source]);
2297 } 2643 }
2298 2644
2299 void test_invalidReferenceToThis_staticVariableInitializer() { 2645 void test_invalidReferenceToThis_staticVariableInitializer() {
2300 Source source = addSource(EngineTestCase.createSource(["class A {", " stati c A f = this;", "}"])); 2646 Source source = addSource(r'''
2647 class A {
2648 static A f = this;
2649 }''');
2301 resolve(source); 2650 resolve(source);
2302 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 2651 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
2303 verify([source]); 2652 verify([source]);
2304 } 2653 }
2305 2654
2306 void test_invalidReferenceToThis_superInitializer() { 2655 void test_invalidReferenceToThis_superInitializer() {
2307 Source source = addSource(EngineTestCase.createSource([ 2656 Source source = addSource(r'''
2308 "class A {", 2657 class A {
2309 " A(var x) {}", 2658 A(var x) {}
2310 "}", 2659 }
2311 "class B extends A {", 2660 class B extends A {
2312 " B() : super(this);", 2661 B() : super(this);
2313 "}"])); 2662 }''');
2314 resolve(source); 2663 resolve(source);
2315 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 2664 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
2316 verify([source]); 2665 verify([source]);
2317 } 2666 }
2318 2667
2319 void test_invalidReferenceToThis_topLevelFunction() { 2668 void test_invalidReferenceToThis_topLevelFunction() {
2320 Source source = addSource("f() { return this; }"); 2669 Source source = addSource("f() { return this; }");
2321 resolve(source); 2670 resolve(source);
2322 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 2671 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
2323 verify([source]); 2672 verify([source]);
2324 } 2673 }
2325 2674
2326 void test_invalidReferenceToThis_variableInitializer() { 2675 void test_invalidReferenceToThis_variableInitializer() {
2327 Source source = addSource("int x = this;"); 2676 Source source = addSource("int x = this;");
2328 resolve(source); 2677 resolve(source);
2329 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 2678 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
2330 verify([source]); 2679 verify([source]);
2331 } 2680 }
2332 2681
2333 void test_invalidTypeArgumentInConstList() { 2682 void test_invalidTypeArgumentInConstList() {
2334 Source source = addSource(EngineTestCase.createSource([ 2683 Source source = addSource(r'''
2335 "class A<E> {", 2684 class A<E> {
2336 " m() {", 2685 m() {
2337 " return const <E>[];", 2686 return const <E>[];
2338 " }", 2687 }
2339 "}"])); 2688 }''');
2340 resolve(source); 2689 resolve(source);
2341 assertErrors(source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LI ST]); 2690 assertErrors(source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LI ST]);
2342 verify([source]); 2691 verify([source]);
2343 } 2692 }
2344 2693
2345 void test_invalidTypeArgumentInConstMap() { 2694 void test_invalidTypeArgumentInConstMap() {
2346 Source source = addSource(EngineTestCase.createSource([ 2695 Source source = addSource(r'''
2347 "class A<E> {", 2696 class A<E> {
2348 " m() {", 2697 m() {
2349 " return const <String, E>{};", 2698 return const <String, E>{};
2350 " }", 2699 }
2351 "}"])); 2700 }''');
2352 resolve(source); 2701 resolve(source);
2353 assertErrors(source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MA P]); 2702 assertErrors(source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MA P]);
2354 verify([source]); 2703 verify([source]);
2355 } 2704 }
2356 2705
2357 void test_invalidUri_export() { 2706 void test_invalidUri_export() {
2358 Source source = addSource(EngineTestCase.createSource(["export 'ht:';"])); 2707 Source source = addSource("export 'ht:';");
2359 resolve(source); 2708 resolve(source);
2360 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); 2709 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]);
2361 } 2710 }
2362 2711
2363 void test_invalidUri_import() { 2712 void test_invalidUri_import() {
2364 Source source = addSource(EngineTestCase.createSource(["import 'ht:';"])); 2713 Source source = addSource("import 'ht:';");
2365 resolve(source); 2714 resolve(source);
2366 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); 2715 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]);
2367 } 2716 }
2368 2717
2369 void test_invalidUri_part() { 2718 void test_invalidUri_part() {
2370 Source source = addSource(EngineTestCase.createSource(["part 'ht:';"])); 2719 Source source = addSource("part 'ht:';");
2371 resolve(source); 2720 resolve(source);
2372 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); 2721 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]);
2373 } 2722 }
2374 2723
2375 void test_labelInOuterScope() { 2724 void test_labelInOuterScope() {
2376 Source source = addSource(EngineTestCase.createSource([ 2725 Source source = addSource(r'''
2377 "class A {", 2726 class A {
2378 " void m(int i) {", 2727 void m(int i) {
2379 " l: while (i > 0) {", 2728 l: while (i > 0) {
2380 " void f() {", 2729 void f() {
2381 " break l;", 2730 break l;
2382 " };", 2731 };
2383 " }", 2732 }
2384 " }", 2733 }
2385 "}"])); 2734 }''');
2386 resolve(source); 2735 resolve(source);
2387 assertErrors(source, [CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE]); 2736 assertErrors(source, [CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE]);
2388 // We cannot verify resolution with unresolvable labels 2737 // We cannot verify resolution with unresolvable labels
2389 } 2738 }
2390 2739
2391 void test_labelUndefined_break() { 2740 void test_labelUndefined_break() {
2392 Source source = addSource(EngineTestCase.createSource([ 2741 Source source = addSource(r'''
2393 "f() {", 2742 f() {
2394 " x: while (true) {", 2743 x: while (true) {
2395 " break y;", 2744 break y;
2396 " }", 2745 }
2397 "}"])); 2746 }''');
2398 resolve(source); 2747 resolve(source);
2399 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); 2748 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]);
2400 // We cannot verify resolution with undefined labels 2749 // We cannot verify resolution with undefined labels
2401 } 2750 }
2402 2751
2403 void test_labelUndefined_continue() { 2752 void test_labelUndefined_continue() {
2404 Source source = addSource(EngineTestCase.createSource([ 2753 Source source = addSource(r'''
2405 "f() {", 2754 f() {
2406 " x: while (true) {", 2755 x: while (true) {
2407 " continue y;", 2756 continue y;
2408 " }", 2757 }
2409 "}"])); 2758 }''');
2410 resolve(source); 2759 resolve(source);
2411 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); 2760 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]);
2412 // We cannot verify resolution with undefined labels 2761 // We cannot verify resolution with undefined labels
2413 } 2762 }
2414 2763
2415 void test_memberWithClassName_field() { 2764 void test_memberWithClassName_field() {
2416 Source source = addSource(EngineTestCase.createSource(["class A {", " int A = 0;", "}"])); 2765 Source source = addSource(r'''
2766 class A {
2767 int A = 0;
2768 }''');
2417 resolve(source); 2769 resolve(source);
2418 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); 2770 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]);
2419 verify([source]); 2771 verify([source]);
2420 } 2772 }
2421 2773
2422 void test_memberWithClassName_field2() { 2774 void test_memberWithClassName_field2() {
2423 Source source = addSource(EngineTestCase.createSource(["class A {", " int z , A, b = 0;", "}"])); 2775 Source source = addSource(r'''
2776 class A {
2777 int z, A, b = 0;
2778 }''');
2424 resolve(source); 2779 resolve(source);
2425 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); 2780 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]);
2426 verify([source]); 2781 verify([source]);
2427 } 2782 }
2428 2783
2429 void test_memberWithClassName_getter() { 2784 void test_memberWithClassName_getter() {
2430 Source source = addSource(EngineTestCase.createSource(["class A {", " get A => 0;", "}"])); 2785 Source source = addSource(r'''
2786 class A {
2787 get A => 0;
2788 }''');
2431 resolve(source); 2789 resolve(source);
2432 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); 2790 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]);
2433 verify([source]); 2791 verify([source]);
2434 } 2792 }
2435 2793
2436 void test_memberWithClassName_method() { 2794 void test_memberWithClassName_method() {
2437 // no test because indistinguishable from constructor 2795 // no test because indistinguishable from constructor
2438 } 2796 }
2439 2797
2440 void test_methodAndGetterWithSameName() { 2798 void test_methodAndGetterWithSameName() {
2441 Source source = addSource(EngineTestCase.createSource(["class A {", " get x => 0;", " x(y) {}", "}"])); 2799 Source source = addSource(r'''
2800 class A {
2801 get x => 0;
2802 x(y) {}
2803 }''');
2442 resolve(source); 2804 resolve(source);
2443 assertErrors(source, [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME] ); 2805 assertErrors(source, [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME] );
2444 verify([source]); 2806 verify([source]);
2445 } 2807 }
2446 2808
2447 void test_missingEnumConstantInSwitch() { 2809 void test_missingEnumConstantInSwitch() {
2448 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); 2810 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
2449 analysisOptions.enableEnum = true; 2811 analysisOptions.enableEnum = true;
2450 resetWithOptions(analysisOptions); 2812 resetWithOptions(analysisOptions);
2451 Source source = addSource(EngineTestCase.createSource([ 2813 Source source = addSource(r'''
2452 "enum E { ONE, TWO, THREE, FOUR }", 2814 enum E { ONE, TWO, THREE, FOUR }
2453 "bool odd(E e) {", 2815 bool odd(E e) {
2454 " switch (e) {", 2816 switch (e) {
2455 " case E.ONE:", 2817 case E.ONE:
2456 " case E.THREE: return true;", 2818 case E.THREE: return true;
2457 " }", 2819 }
2458 " return false;", 2820 return false;
2459 "}"])); 2821 }''');
2460 resolve(source); 2822 resolve(source);
2461 assertErrors(source, [ 2823 assertErrors(source, [
2462 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, 2824 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH,
2463 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH]); 2825 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH]);
2464 verify([source]); 2826 verify([source]);
2465 } 2827 }
2466 2828
2467 void test_mixinDeclaresConstructor_classDeclaration() { 2829 void test_mixinDeclaresConstructor_classDeclaration() {
2468 Source source = addSource(EngineTestCase.createSource([ 2830 Source source = addSource(r'''
2469 "class A {", 2831 class A {
2470 " A() {}", 2832 A() {}
2471 "}", 2833 }
2472 "class B extends Object with A {}"])); 2834 class B extends Object with A {}''');
2473 resolve(source); 2835 resolve(source);
2474 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); 2836 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
2475 verify([source]); 2837 verify([source]);
2476 } 2838 }
2477 2839
2478 void test_mixinDeclaresConstructor_typeAlias() { 2840 void test_mixinDeclaresConstructor_typeAlias() {
2479 Source source = addSource(EngineTestCase.createSource(["class A {", " A() { }", "}", "class B = Object with A;"])); 2841 Source source = addSource(r'''
2842 class A {
2843 A() {}
2844 }
2845 class B = Object with A;''');
2480 resolve(source); 2846 resolve(source);
2481 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); 2847 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
2482 verify([source]); 2848 verify([source]);
2483 } 2849 }
2484 2850
2485 void test_mixinDeferredClass() { 2851 void test_mixinDeferredClass() {
2486 resolveWithAndWithoutExperimental(<String> [ 2852 resolveWithAndWithoutExperimental(<String> [
2487 EngineTestCase.createSource(["library lib1;", "class A {}"]), 2853 r'''
2488 EngineTestCase.createSource([ 2854 library lib1;
2489 "library root;", 2855 class A {}''',
2490 "import 'lib1.dart' deferred as a;", 2856 r'''
2491 "class B extends Object with a.A {}"])], <ErrorCode> [ParserErrorCode.DE FERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.MIXIN_DEFERRED_ CLASS]); 2857 library root;
2858 import 'lib1.dart' deferred as a;
2859 class B extends Object with a.A {}'''], <ErrorCode> [ParserErrorCode.DEFERRED_IM PORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]);
2492 } 2860 }
2493 2861
2494 void test_mixinDeferredClass_classTypeAlias() { 2862 void test_mixinDeferredClass_classTypeAlias() {
2495 resolveWithAndWithoutExperimental(<String> [ 2863 resolveWithAndWithoutExperimental(<String> [
2496 EngineTestCase.createSource(["library lib1;", "class A {}"]), 2864 r'''
2497 EngineTestCase.createSource([ 2865 library lib1;
2498 "library root;", 2866 class A {}''',
2499 "import 'lib1.dart' deferred as a;", 2867 r'''
2500 "class B {}", 2868 library root;
2501 "class C = B with a.A;"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORT S_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]); 2869 import 'lib1.dart' deferred as a;
2870 class B {}
2871 class C = B with a.A;'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUP PORTED], <ErrorCode> [CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]);
2502 } 2872 }
2503 2873
2504 void test_mixinInheritsFromNotObject_classDeclaration_extends() { 2874 void test_mixinInheritsFromNotObject_classDeclaration_extends() {
2505 Source source = addSource(EngineTestCase.createSource([ 2875 Source source = addSource(r'''
2506 "class A {}", 2876 class A {}
2507 "class B extends A {}", 2877 class B extends A {}
2508 "class C extends Object with B {}"])); 2878 class C extends Object with B {}''');
2509 resolve(source); 2879 resolve(source);
2510 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 2880 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
2511 verify([source]); 2881 verify([source]);
2512 } 2882 }
2513 2883
2514 void test_mixinInheritsFromNotObject_classDeclaration_with() { 2884 void test_mixinInheritsFromNotObject_classDeclaration_with() {
2515 Source source = addSource(EngineTestCase.createSource([ 2885 Source source = addSource(r'''
2516 "class A {}", 2886 class A {}
2517 "class B extends Object with A {}", 2887 class B extends Object with A {}
2518 "class C extends Object with B {}"])); 2888 class C extends Object with B {}''');
2519 resolve(source); 2889 resolve(source);
2520 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 2890 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
2521 verify([source]); 2891 verify([source]);
2522 } 2892 }
2523 2893
2524 void test_mixinInheritsFromNotObject_typeAlias_extends() { 2894 void test_mixinInheritsFromNotObject_typeAlias_extends() {
2525 Source source = addSource(EngineTestCase.createSource([ 2895 Source source = addSource(r'''
2526 "class A {}", 2896 class A {}
2527 "class B extends A {}", 2897 class B extends A {}
2528 "class C = Object with B;"])); 2898 class C = Object with B;''');
2529 resolve(source); 2899 resolve(source);
2530 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 2900 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
2531 verify([source]); 2901 verify([source]);
2532 } 2902 }
2533 2903
2534 void test_mixinInheritsFromNotObject_typeAlias_with() { 2904 void test_mixinInheritsFromNotObject_typeAlias_with() {
2535 Source source = addSource(EngineTestCase.createSource([ 2905 Source source = addSource(r'''
2536 "class A {}", 2906 class A {}
2537 "class B extends Object with A {}", 2907 class B extends Object with A {}
2538 "class C = Object with B;"])); 2908 class C = Object with B;''');
2539 resolve(source); 2909 resolve(source);
2540 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 2910 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
2541 verify([source]); 2911 verify([source]);
2542 } 2912 }
2543 2913
2544 void test_mixinOfDisallowedClass_class_bool() { 2914 void test_mixinOfDisallowedClass_class_bool() {
2545 Source source = addSource(EngineTestCase.createSource(["class A extends Obje ct with bool {}"])); 2915 Source source = addSource("class A extends Object with bool {}");
2546 resolve(source); 2916 resolve(source);
2547 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2917 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2548 verify([source]); 2918 verify([source]);
2549 } 2919 }
2550 2920
2551 void test_mixinOfDisallowedClass_class_double() { 2921 void test_mixinOfDisallowedClass_class_double() {
2552 Source source = addSource(EngineTestCase.createSource(["class A extends Obje ct with double {}"])); 2922 Source source = addSource("class A extends Object with double {}");
2553 resolve(source); 2923 resolve(source);
2554 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2924 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2555 verify([source]); 2925 verify([source]);
2556 } 2926 }
2557 2927
2558 void test_mixinOfDisallowedClass_class_int() { 2928 void test_mixinOfDisallowedClass_class_int() {
2559 Source source = addSource(EngineTestCase.createSource(["class A extends Obje ct with int {}"])); 2929 Source source = addSource("class A extends Object with int {}");
2560 resolve(source); 2930 resolve(source);
2561 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2931 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2562 verify([source]); 2932 verify([source]);
2563 } 2933 }
2564 2934
2565 void test_mixinOfDisallowedClass_class_Null() { 2935 void test_mixinOfDisallowedClass_class_Null() {
2566 Source source = addSource(EngineTestCase.createSource(["class A extends Obje ct with Null {}"])); 2936 Source source = addSource("class A extends Object with Null {}");
2567 resolve(source); 2937 resolve(source);
2568 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2938 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2569 verify([source]); 2939 verify([source]);
2570 } 2940 }
2571 2941
2572 void test_mixinOfDisallowedClass_class_num() { 2942 void test_mixinOfDisallowedClass_class_num() {
2573 Source source = addSource(EngineTestCase.createSource(["class A extends Obje ct with num {}"])); 2943 Source source = addSource("class A extends Object with num {}");
2574 resolve(source); 2944 resolve(source);
2575 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2945 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2576 verify([source]); 2946 verify([source]);
2577 } 2947 }
2578 2948
2579 void test_mixinOfDisallowedClass_class_String() { 2949 void test_mixinOfDisallowedClass_class_String() {
2580 Source source = addSource(EngineTestCase.createSource(["class A extends Obje ct with String {}"])); 2950 Source source = addSource("class A extends Object with String {}");
2581 resolve(source); 2951 resolve(source);
2582 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2952 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2583 verify([source]); 2953 verify([source]);
2584 } 2954 }
2585 2955
2586 void test_mixinOfDisallowedClass_classTypeAlias_bool() { 2956 void test_mixinOfDisallowedClass_classTypeAlias_bool() {
2587 Source source = addSource(EngineTestCase.createSource(["class A {}", "class C = A with bool;"])); 2957 Source source = addSource(r'''
2958 class A {}
2959 class C = A with bool;''');
2588 resolve(source); 2960 resolve(source);
2589 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2961 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2590 verify([source]); 2962 verify([source]);
2591 } 2963 }
2592 2964
2593 void test_mixinOfDisallowedClass_classTypeAlias_double() { 2965 void test_mixinOfDisallowedClass_classTypeAlias_double() {
2594 Source source = addSource(EngineTestCase.createSource(["class A {}", "class C = A with double;"])); 2966 Source source = addSource(r'''
2967 class A {}
2968 class C = A with double;''');
2595 resolve(source); 2969 resolve(source);
2596 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2970 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2597 verify([source]); 2971 verify([source]);
2598 } 2972 }
2599 2973
2600 void test_mixinOfDisallowedClass_classTypeAlias_int() { 2974 void test_mixinOfDisallowedClass_classTypeAlias_int() {
2601 Source source = addSource(EngineTestCase.createSource(["class A {}", "class C = A with int;"])); 2975 Source source = addSource(r'''
2976 class A {}
2977 class C = A with int;''');
2602 resolve(source); 2978 resolve(source);
2603 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2979 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2604 verify([source]); 2980 verify([source]);
2605 } 2981 }
2606 2982
2607 void test_mixinOfDisallowedClass_classTypeAlias_Null() { 2983 void test_mixinOfDisallowedClass_classTypeAlias_Null() {
2608 Source source = addSource(EngineTestCase.createSource(["class A {}", "class C = A with Null;"])); 2984 Source source = addSource(r'''
2985 class A {}
2986 class C = A with Null;''');
2609 resolve(source); 2987 resolve(source);
2610 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2988 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2611 verify([source]); 2989 verify([source]);
2612 } 2990 }
2613 2991
2614 void test_mixinOfDisallowedClass_classTypeAlias_num() { 2992 void test_mixinOfDisallowedClass_classTypeAlias_num() {
2615 Source source = addSource(EngineTestCase.createSource(["class A {}", "class C = A with num;"])); 2993 Source source = addSource(r'''
2994 class A {}
2995 class C = A with num;''');
2616 resolve(source); 2996 resolve(source);
2617 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 2997 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2618 verify([source]); 2998 verify([source]);
2619 } 2999 }
2620 3000
2621 void test_mixinOfDisallowedClass_classTypeAlias_String() { 3001 void test_mixinOfDisallowedClass_classTypeAlias_String() {
2622 Source source = addSource(EngineTestCase.createSource(["class A {}", "class C = A with String;"])); 3002 Source source = addSource(r'''
3003 class A {}
3004 class C = A with String;''');
2623 resolve(source); 3005 resolve(source);
2624 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3006 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2625 verify([source]); 3007 verify([source]);
2626 } 3008 }
2627 3009
2628 void test_mixinOfDisallowedClass_classTypeAlias_String_num() { 3010 void test_mixinOfDisallowedClass_classTypeAlias_String_num() {
2629 Source source = addSource(EngineTestCase.createSource(["class A {}", "class C = A with String, num;"])); 3011 Source source = addSource(r'''
3012 class A {}
3013 class C = A with String, num;''');
2630 resolve(source); 3014 resolve(source);
2631 assertErrors(source, [ 3015 assertErrors(source, [
2632 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, 3016 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS,
2633 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3017 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
2634 verify([source]); 3018 verify([source]);
2635 } 3019 }
2636 3020
2637 void test_mixinOfEnum() { 3021 void test_mixinOfEnum() {
2638 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); 3022 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
2639 analysisOptions.enableEnum = true; 3023 analysisOptions.enableEnum = true;
2640 resetWithOptions(analysisOptions); 3024 resetWithOptions(analysisOptions);
2641 Source source = addSource(EngineTestCase.createSource(["enum E { ONE }", "cl ass A extends Object with E {}"])); 3025 Source source = addSource(r'''
3026 enum E { ONE }
3027 class A extends Object with E {}''');
2642 resolve(source); 3028 resolve(source);
2643 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_ENUM]); 3029 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_ENUM]);
2644 verify([source]); 3030 verify([source]);
2645 } 3031 }
2646 3032
2647 void test_mixinOfNonClass_class() { 3033 void test_mixinOfNonClass_class() {
2648 Source source = addSource(EngineTestCase.createSource(["int A;", "class B ex tends Object with A {}"])); 3034 Source source = addSource(r'''
3035 int A;
3036 class B extends Object with A {}''');
2649 resolve(source); 3037 resolve(source);
2650 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); 3038 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]);
2651 verify([source]); 3039 verify([source]);
2652 } 3040 }
2653 3041
2654 void test_mixinOfNonClass_typeAlias() { 3042 void test_mixinOfNonClass_typeAlias() {
2655 Source source = addSource(EngineTestCase.createSource(["class A {}", "int B; ", "class C = A with B;"])); 3043 Source source = addSource(r'''
3044 class A {}
3045 int B;
3046 class C = A with B;''');
2656 resolve(source); 3047 resolve(source);
2657 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); 3048 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]);
2658 verify([source]); 3049 verify([source]);
2659 } 3050 }
2660 3051
2661 void test_mixinReferencesSuper() { 3052 void test_mixinReferencesSuper() {
2662 Source source = addSource(EngineTestCase.createSource([ 3053 Source source = addSource(r'''
2663 "class A {", 3054 class A {
2664 " toString() => super.toString();", 3055 toString() => super.toString();
2665 "}", 3056 }
2666 "class B extends Object with A {}"])); 3057 class B extends Object with A {}''');
2667 resolve(source); 3058 resolve(source);
2668 assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]); 3059 assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]);
2669 verify([source]); 3060 verify([source]);
2670 } 3061 }
2671 3062
2672 void test_mixinWithNonClassSuperclass_class() { 3063 void test_mixinWithNonClassSuperclass_class() {
2673 Source source = addSource(EngineTestCase.createSource(["int A;", "class B {} ", "class C extends A with B {}"])); 3064 Source source = addSource(r'''
3065 int A;
3066 class B {}
3067 class C extends A with B {}''');
2674 resolve(source); 3068 resolve(source);
2675 assertErrors(source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]) ; 3069 assertErrors(source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]) ;
2676 verify([source]); 3070 verify([source]);
2677 } 3071 }
2678 3072
2679 void test_mixinWithNonClassSuperclass_typeAlias() { 3073 void test_mixinWithNonClassSuperclass_typeAlias() {
2680 Source source = addSource(EngineTestCase.createSource(["int A;", "class B {} ", "class C = A with B;"])); 3074 Source source = addSource(r'''
3075 int A;
3076 class B {}
3077 class C = A with B;''');
2681 resolve(source); 3078 resolve(source);
2682 assertErrors(source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]) ; 3079 assertErrors(source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]) ;
2683 verify([source]); 3080 verify([source]);
2684 } 3081 }
2685 3082
2686 void test_multipleRedirectingConstructorInvocations() { 3083 void test_multipleRedirectingConstructorInvocations() {
2687 Source source = addSource(EngineTestCase.createSource([ 3084 Source source = addSource(r'''
2688 "class A {", 3085 class A {
2689 " A() : this.a(), this.b();", 3086 A() : this.a(), this.b();
2690 " A.a() {}", 3087 A.a() {}
2691 " A.b() {}", 3088 A.b() {}
2692 "}"])); 3089 }''');
2693 resolve(source); 3090 resolve(source);
2694 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_ INVOCATIONS]); 3091 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_ INVOCATIONS]);
2695 verify([source]); 3092 verify([source]);
2696 } 3093 }
2697 3094
2698 void test_multipleSuperInitializers() { 3095 void test_multipleSuperInitializers() {
2699 Source source = addSource(EngineTestCase.createSource([ 3096 Source source = addSource(r'''
2700 "class A {}", 3097 class A {}
2701 "class B extends A {", 3098 class B extends A {
2702 " B() : super(), super() {}", 3099 B() : super(), super() {}
2703 "}"])); 3100 }''');
2704 resolve(source); 3101 resolve(source);
2705 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]); 3102 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]);
2706 verify([source]); 3103 verify([source]);
2707 } 3104 }
2708 3105
2709 void test_nativeClauseInNonSDKCode() { 3106 void test_nativeClauseInNonSDKCode() {
2710 // TODO(jwren) Move this test somewhere else: This test verifies a parser er ror code is generated 3107 // TODO(jwren) Move this test somewhere else: This test verifies a parser er ror code is generated
2711 // through the ErrorVerifier, it is not a CompileTimeErrorCode. 3108 // through the ErrorVerifier, it is not a CompileTimeErrorCode.
2712 Source source = addSource(EngineTestCase.createSource(["class A native 'stri ng' {}"])); 3109 Source source = addSource("class A native 'string' {}");
2713 resolve(source); 3110 resolve(source);
2714 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); 3111 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]);
2715 verify([source]); 3112 verify([source]);
2716 } 3113 }
2717 3114
2718 void test_nativeFunctionBodyInNonSDKCode_function() { 3115 void test_nativeFunctionBodyInNonSDKCode_function() {
2719 // TODO(jwren) Move this test somewhere else: This test verifies a parser er ror code is generated 3116 // TODO(jwren) Move this test somewhere else: This test verifies a parser er ror code is generated
2720 // through the ErrorVerifier, it is not a CompileTimeErrorCode. 3117 // through the ErrorVerifier, it is not a CompileTimeErrorCode.
2721 Source source = addSource(EngineTestCase.createSource(["int m(a) native 'str ing';"])); 3118 Source source = addSource("int m(a) native 'string';");
2722 resolve(source); 3119 resolve(source);
2723 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]) ; 3120 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]) ;
2724 verify([source]); 3121 verify([source]);
2725 } 3122 }
2726 3123
2727 void test_nativeFunctionBodyInNonSDKCode_method() { 3124 void test_nativeFunctionBodyInNonSDKCode_method() {
2728 // TODO(jwren) Move this test somewhere else: This test verifies a parser er ror code is generated 3125 // TODO(jwren) Move this test somewhere else: This test verifies a parser er ror code is generated
2729 // through the ErrorVerifier, it is not a CompileTimeErrorCode. 3126 // through the ErrorVerifier, it is not a CompileTimeErrorCode.
2730 Source source = addSource(EngineTestCase.createSource(["class A{", " static int m(a) native 'string';", "}"])); 3127 Source source = addSource(r'''
3128 class A{
3129 static int m(a) native 'string';
3130 }''');
2731 resolve(source); 3131 resolve(source);
2732 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]) ; 3132 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]) ;
2733 verify([source]); 3133 verify([source]);
2734 } 3134 }
2735 3135
2736 void test_noAnnotationConstructorArguments() { 3136 void test_noAnnotationConstructorArguments() {
2737 Source source = addSource(EngineTestCase.createSource(["class A {", " const A();", "}", "@A", "main() {", "}"])); 3137 Source source = addSource(r'''
3138 class A {
3139 const A();
3140 }
3141 @A
3142 main() {
3143 }''');
2738 resolve(source); 3144 resolve(source);
2739 assertErrors(source, [CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMEN TS]); 3145 assertErrors(source, [CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMEN TS]);
2740 verify([source]); 3146 verify([source]);
2741 } 3147 }
2742 3148
2743 void test_noDefaultSuperConstructorExplicit() { 3149 void test_noDefaultSuperConstructorExplicit() {
2744 Source source = addSource(EngineTestCase.createSource([ 3150 Source source = addSource(r'''
2745 "class A {", 3151 class A {
2746 " A(p);", 3152 A(p);
2747 "}", 3153 }
2748 "class B extends A {", 3154 class B extends A {
2749 " B() {}", 3155 B() {}
2750 "}"])); 3156 }''');
2751 resolve(source); 3157 resolve(source);
2752 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPL ICIT]); 3158 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPL ICIT]);
2753 verify([source]); 3159 verify([source]);
2754 } 3160 }
2755 3161
2756 void test_noDefaultSuperConstructorImplicit_superHasParameters() { 3162 void test_noDefaultSuperConstructorImplicit_superHasParameters() {
2757 Source source = addSource(EngineTestCase.createSource(["class A {", " A(p); ", "}", "class B extends A {", "}"])); 3163 Source source = addSource(r'''
3164 class A {
3165 A(p);
3166 }
3167 class B extends A {
3168 }''');
2758 resolve(source); 3169 resolve(source);
2759 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL ICIT]); 3170 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL ICIT]);
2760 verify([source]); 3171 verify([source]);
2761 } 3172 }
2762 3173
2763 void test_noDefaultSuperConstructorImplicit_superOnlyNamed() { 3174 void test_noDefaultSuperConstructorImplicit_superOnlyNamed() {
2764 Source source = addSource(EngineTestCase.createSource(["class A { A.named() {} }", "class B extends A {}"])); 3175 Source source = addSource(r'''
3176 class A { A.named() {} }
3177 class B extends A {}''');
2765 resolve(source); 3178 resolve(source);
2766 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL ICIT]); 3179 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL ICIT]);
2767 verify([source]); 3180 verify([source]);
2768 } 3181 }
2769 3182
2770 void test_nonConstantAnnotationConstructor_named() { 3183 void test_nonConstantAnnotationConstructor_named() {
2771 Source source = addSource(EngineTestCase.createSource([ 3184 Source source = addSource(r'''
2772 "class A {", 3185 class A {
2773 " A.fromInt() {}", 3186 A.fromInt() {}
2774 "}", 3187 }
2775 "@A.fromInt()", 3188 @A.fromInt()
2776 "main() {", 3189 main() {
2777 "}"])); 3190 }''');
2778 resolve(source); 3191 resolve(source);
2779 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCT OR]); 3192 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCT OR]);
2780 verify([source]); 3193 verify([source]);
2781 } 3194 }
2782 3195
2783 void test_nonConstantAnnotationConstructor_unnamed() { 3196 void test_nonConstantAnnotationConstructor_unnamed() {
2784 Source source = addSource(EngineTestCase.createSource(["class A {", " A() { }", "}", "@A()", "main() {", "}"])); 3197 Source source = addSource(r'''
3198 class A {
3199 A() {}
3200 }
3201 @A()
3202 main() {
3203 }''');
2785 resolve(source); 3204 resolve(source);
2786 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCT OR]); 3205 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCT OR]);
2787 verify([source]); 3206 verify([source]);
2788 } 3207 }
2789 3208
2790 void test_nonConstantDefaultValue_function_named() { 3209 void test_nonConstantDefaultValue_function_named() {
2791 Source source = addSource(EngineTestCase.createSource(["int y;", "f({x : y}) {}"])); 3210 Source source = addSource(r'''
3211 int y;
3212 f({x : y}) {}''');
2792 resolve(source); 3213 resolve(source);
2793 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3214 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
2794 verify([source]); 3215 verify([source]);
2795 } 3216 }
2796 3217
2797 void test_nonConstantDefaultValue_function_positional() { 3218 void test_nonConstantDefaultValue_function_positional() {
2798 Source source = addSource(EngineTestCase.createSource(["int y;", "f([x = y]) {}"])); 3219 Source source = addSource(r'''
3220 int y;
3221 f([x = y]) {}''');
2799 resolve(source); 3222 resolve(source);
2800 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3223 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
2801 verify([source]); 3224 verify([source]);
2802 } 3225 }
2803 3226
2804 void test_nonConstantDefaultValue_inConstructor_named() { 3227 void test_nonConstantDefaultValue_inConstructor_named() {
2805 Source source = addSource(EngineTestCase.createSource(["class A {", " int y ;", " A({x : y}) {}", "}"])); 3228 Source source = addSource(r'''
3229 class A {
3230 int y;
3231 A({x : y}) {}
3232 }''');
2806 resolve(source); 3233 resolve(source);
2807 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3234 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
2808 verify([source]); 3235 verify([source]);
2809 } 3236 }
2810 3237
2811 void test_nonConstantDefaultValue_inConstructor_positional() { 3238 void test_nonConstantDefaultValue_inConstructor_positional() {
2812 Source source = addSource(EngineTestCase.createSource(["class A {", " int y ;", " A([x = y]) {}", "}"])); 3239 Source source = addSource(r'''
3240 class A {
3241 int y;
3242 A([x = y]) {}
3243 }''');
2813 resolve(source); 3244 resolve(source);
2814 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3245 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
2815 verify([source]); 3246 verify([source]);
2816 } 3247 }
2817 3248
2818 void test_nonConstantDefaultValue_method_named() { 3249 void test_nonConstantDefaultValue_method_named() {
2819 Source source = addSource(EngineTestCase.createSource(["class A {", " int y ;", " m({x : y}) {}", "}"])); 3250 Source source = addSource(r'''
3251 class A {
3252 int y;
3253 m({x : y}) {}
3254 }''');
2820 resolve(source); 3255 resolve(source);
2821 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3256 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
2822 verify([source]); 3257 verify([source]);
2823 } 3258 }
2824 3259
2825 void test_nonConstantDefaultValue_method_positional() { 3260 void test_nonConstantDefaultValue_method_positional() {
2826 Source source = addSource(EngineTestCase.createSource(["class A {", " int y ;", " m([x = y]) {}", "}"])); 3261 Source source = addSource(r'''
3262 class A {
3263 int y;
3264 m([x = y]) {}
3265 }''');
2827 resolve(source); 3266 resolve(source);
2828 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3267 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
2829 verify([source]); 3268 verify([source]);
2830 } 3269 }
2831 3270
2832 void test_nonConstantDefaultValueFromDeferredLibrary() { 3271 void test_nonConstantDefaultValueFromDeferredLibrary() {
2833 resolveWithAndWithoutExperimental(<String> [ 3272 resolveWithAndWithoutExperimental(<String> [
2834 EngineTestCase.createSource(["library lib1;", "const V = 1;"]), 3273 r'''
2835 EngineTestCase.createSource([ 3274 library lib1;
2836 "library root;", 3275 const V = 1;''',
2837 "import 'lib1.dart' deferred as a;", 3276 r'''
2838 "f({x : a.V}) {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_ SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DE FERRED_LIBRARY]); 3277 library root;
3278 import 'lib1.dart' deferred as a;
3279 f({x : a.V}) {}'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED ], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LI BRARY]);
2839 } 3280 }
2840 3281
2841 void test_nonConstantDefaultValueFromDeferredLibrary_nested() { 3282 void test_nonConstantDefaultValueFromDeferredLibrary_nested() {
2842 resolveWithAndWithoutExperimental(<String> [ 3283 resolveWithAndWithoutExperimental(<String> [
2843 EngineTestCase.createSource(["library lib1;", "const V = 1;"]), 3284 r'''
2844 EngineTestCase.createSource([ 3285 library lib1;
2845 "library root;", 3286 const V = 1;''',
2846 "import 'lib1.dart' deferred as a;", 3287 r'''
2847 "f({x : a.V + 1}) {}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_ NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FRO M_DEFERRED_LIBRARY]); 3288 library root;
3289 import 'lib1.dart' deferred as a;
3290 f({x : a.V + 1}) {}'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPO RTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRE D_LIBRARY]);
2848 } 3291 }
2849 3292
2850 void test_nonConstCaseExpression() { 3293 void test_nonConstCaseExpression() {
2851 Source source = addSource(EngineTestCase.createSource([ 3294 Source source = addSource(r'''
2852 "f(int p, int q) {", 3295 f(int p, int q) {
2853 " switch (p) {", 3296 switch (p) {
2854 " case 3 + q:", 3297 case 3 + q:
2855 " break;", 3298 break;
2856 " }", 3299 }
2857 "}"])); 3300 }''');
2858 resolve(source); 3301 resolve(source);
2859 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION]); 3302 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION]);
2860 verify([source]); 3303 verify([source]);
2861 } 3304 }
2862 3305
2863 void test_nonConstCaseExpressionFromDeferredLibrary() { 3306 void test_nonConstCaseExpressionFromDeferredLibrary() {
2864 resolveWithAndWithoutExperimental(<String> [ 3307 resolveWithAndWithoutExperimental(<String> [
2865 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3308 r'''
2866 EngineTestCase.createSource([ 3309 library lib1;
2867 "library root;", 3310 const int c = 1;''',
2868 "import 'lib1.dart' deferred as a;", 3311 r'''
2869 "main (int p) {", 3312 library root;
2870 " switch (p) {", 3313 import 'lib1.dart' deferred as a;
2871 " case a.c:", 3314 main (int p) {
2872 " break;", 3315 switch (p) {
2873 " }", 3316 case a.c:
2874 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRA RY]); 3317 break;
3318 }
3319 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY]);
2875 } 3320 }
2876 3321
2877 void test_nonConstCaseExpressionFromDeferredLibrary_nested() { 3322 void test_nonConstCaseExpressionFromDeferredLibrary_nested() {
2878 resolveWithAndWithoutExperimental(<String> [ 3323 resolveWithAndWithoutExperimental(<String> [
2879 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3324 r'''
2880 EngineTestCase.createSource([ 3325 library lib1;
2881 "library root;", 3326 const int c = 1;''',
2882 "import 'lib1.dart' deferred as a;", 3327 r'''
2883 "main (int p) {", 3328 library root;
2884 " switch (p) {", 3329 import 'lib1.dart' deferred as a;
2885 " case a.c + 1:", 3330 main (int p) {
2886 " break;", 3331 switch (p) {
2887 " }", 3332 case a.c + 1:
2888 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRA RY]); 3333 break;
3334 }
3335 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY]);
2889 } 3336 }
2890 3337
2891 void test_nonConstListElement() { 3338 void test_nonConstListElement() {
2892 Source source = addSource(EngineTestCase.createSource(["f(a) {", " return c onst [a];", "}"])); 3339 Source source = addSource(r'''
3340 f(a) {
3341 return const [a];
3342 }''');
2893 resolve(source); 3343 resolve(source);
2894 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]); 3344 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
2895 verify([source]); 3345 verify([source]);
2896 } 3346 }
2897 3347
2898 void test_nonConstListElementFromDeferredLibrary() { 3348 void test_nonConstListElementFromDeferredLibrary() {
2899 resolveWithAndWithoutExperimental(<String> [ 3349 resolveWithAndWithoutExperimental(<String> [
2900 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3350 r'''
2901 EngineTestCase.createSource([ 3351 library lib1;
2902 "library root;", 3352 const int c = 1;''',
2903 "import 'lib1.dart' deferred as a;", 3353 r'''
2904 "f() {", 3354 library root;
2905 " return const [a.c];", 3355 import 'lib1.dart' deferred as a;
2906 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY] ); 3356 f() {
3357 return const [a.c];
3358 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]);
2907 } 3359 }
2908 3360
2909 void test_nonConstListElementFromDeferredLibrary_nested() { 3361 void test_nonConstListElementFromDeferredLibrary_nested() {
2910 resolveWithAndWithoutExperimental(<String> [ 3362 resolveWithAndWithoutExperimental(<String> [
2911 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3363 r'''
2912 EngineTestCase.createSource([ 3364 library lib1;
2913 "library root;", 3365 const int c = 1;''',
2914 "import 'lib1.dart' deferred as a;", 3366 r'''
2915 "f() {", 3367 library root;
2916 " return const [a.c + 1];", 3368 import 'lib1.dart' deferred as a;
2917 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY] ); 3369 f() {
3370 return const [a.c + 1];
3371 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]);
2918 } 3372 }
2919 3373
2920 void test_nonConstMapAsExpressionStatement_begin() { 3374 void test_nonConstMapAsExpressionStatement_begin() {
2921 Source source = addSource(EngineTestCase.createSource(["f() {", " {'a' : 0, 'b' : 1}.length;", "}"])); 3375 Source source = addSource(r'''
3376 f() {
3377 {'a' : 0, 'b' : 1}.length;
3378 }''');
2922 resolve(source); 3379 resolve(source);
2923 assertErrors(source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATE MENT]); 3380 assertErrors(source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATE MENT]);
2924 verify([source]); 3381 verify([source]);
2925 } 3382 }
2926 3383
2927 void test_nonConstMapAsExpressionStatement_only() { 3384 void test_nonConstMapAsExpressionStatement_only() {
2928 Source source = addSource(EngineTestCase.createSource(["f() {", " {'a' : 0, 'b' : 1};", "}"])); 3385 Source source = addSource(r'''
3386 f() {
3387 {'a' : 0, 'b' : 1};
3388 }''');
2929 resolve(source); 3389 resolve(source);
2930 assertErrors(source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATE MENT]); 3390 assertErrors(source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATE MENT]);
2931 verify([source]); 3391 verify([source]);
2932 } 3392 }
2933 3393
2934 void test_nonConstMapKey() { 3394 void test_nonConstMapKey() {
2935 Source source = addSource(EngineTestCase.createSource(["f(a) {", " return c onst {a : 0};", "}"])); 3395 Source source = addSource(r'''
3396 f(a) {
3397 return const {a : 0};
3398 }''');
2936 resolve(source); 3399 resolve(source);
2937 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]); 3400 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]);
2938 verify([source]); 3401 verify([source]);
2939 } 3402 }
2940 3403
2941 void test_nonConstMapKeyFromDeferredLibrary() { 3404 void test_nonConstMapKeyFromDeferredLibrary() {
2942 resolveWithAndWithoutExperimental(<String> [ 3405 resolveWithAndWithoutExperimental(<String> [
2943 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3406 r'''
2944 EngineTestCase.createSource([ 3407 library lib1;
2945 "library root;", 3408 const int c = 1;''',
2946 "import 'lib1.dart' deferred as a;", 3409 r'''
2947 "f() {", 3410 library root;
2948 " return const {a.c : 0};", 3411 import 'lib1.dart' deferred as a;
2949 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]); 3412 f() {
3413 return const {a.c : 0};
3414 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]);
2950 } 3415 }
2951 3416
2952 void test_nonConstMapKeyFromDeferredLibrary_nested() { 3417 void test_nonConstMapKeyFromDeferredLibrary_nested() {
2953 resolveWithAndWithoutExperimental(<String> [ 3418 resolveWithAndWithoutExperimental(<String> [
2954 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3419 r'''
2955 EngineTestCase.createSource([ 3420 library lib1;
2956 "library root;", 3421 const int c = 1;''',
2957 "import 'lib1.dart' deferred as a;", 3422 r'''
2958 "f() {", 3423 library root;
2959 " return const {a.c + 1 : 0};", 3424 import 'lib1.dart' deferred as a;
2960 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]); 3425 f() {
3426 return const {a.c + 1 : 0};
3427 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]);
2961 } 3428 }
2962 3429
2963 void test_nonConstMapValue() { 3430 void test_nonConstMapValue() {
2964 Source source = addSource(EngineTestCase.createSource(["f(a) {", " return c onst {'a' : a};", "}"])); 3431 Source source = addSource(r'''
3432 f(a) {
3433 return const {'a' : a};
3434 }''');
2965 resolve(source); 3435 resolve(source);
2966 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]); 3436 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]);
2967 verify([source]); 3437 verify([source]);
2968 } 3438 }
2969 3439
2970 void test_nonConstMapValueFromDeferredLibrary() { 3440 void test_nonConstMapValueFromDeferredLibrary() {
2971 resolveWithAndWithoutExperimental(<String> [ 3441 resolveWithAndWithoutExperimental(<String> [
2972 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3442 r'''
2973 EngineTestCase.createSource([ 3443 library lib1;
2974 "library root;", 3444 const int c = 1;''',
2975 "import 'lib1.dart' deferred as a;", 3445 r'''
2976 "f() {", 3446 library root;
2977 " return const {'a' : a.c};", 3447 import 'lib1.dart' deferred as a;
2978 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]); 3448 f() {
3449 return const {'a' : a.c};
3450 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]);
2979 } 3451 }
2980 3452
2981 void test_nonConstMapValueFromDeferredLibrary_nested() { 3453 void test_nonConstMapValueFromDeferredLibrary_nested() {
2982 resolveWithAndWithoutExperimental(<String> [ 3454 resolveWithAndWithoutExperimental(<String> [
2983 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3455 r'''
2984 EngineTestCase.createSource([ 3456 library lib1;
2985 "library root;", 3457 const int c = 1;''',
2986 "import 'lib1.dart' deferred as a;", 3458 r'''
2987 "f() {", 3459 library root;
2988 " return const {'a' : a.c + 1};", 3460 import 'lib1.dart' deferred as a;
2989 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]); 3461 f() {
3462 return const {'a' : a.c + 1};
3463 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]);
2990 } 3464 }
2991 3465
2992 void test_nonConstValueInInitializer_binary_notBool_left() { 3466 void test_nonConstValueInInitializer_binary_notBool_left() {
2993 Source source = addSource(EngineTestCase.createSource([ 3467 Source source = addSource(r'''
2994 "class A {", 3468 class A {
2995 " final bool a;", 3469 final bool a;
2996 " const A(String p) : a = p && true;", 3470 const A(String p) : a = p && true;
2997 "}"])); 3471 }''');
2998 resolve(source); 3472 resolve(source);
2999 assertErrors(source, [ 3473 assertErrors(source, [
3000 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 3474 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
3001 StaticTypeWarningCode.NON_BOOL_OPERAND]); 3475 StaticTypeWarningCode.NON_BOOL_OPERAND]);
3002 verify([source]); 3476 verify([source]);
3003 } 3477 }
3004 3478
3005 void test_nonConstValueInInitializer_binary_notBool_right() { 3479 void test_nonConstValueInInitializer_binary_notBool_right() {
3006 Source source = addSource(EngineTestCase.createSource([ 3480 Source source = addSource(r'''
3007 "class A {", 3481 class A {
3008 " final bool a;", 3482 final bool a;
3009 " const A(String p) : a = true && p;", 3483 const A(String p) : a = true && p;
3010 "}"])); 3484 }''');
3011 resolve(source); 3485 resolve(source);
3012 assertErrors(source, [ 3486 assertErrors(source, [
3013 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 3487 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
3014 StaticTypeWarningCode.NON_BOOL_OPERAND]); 3488 StaticTypeWarningCode.NON_BOOL_OPERAND]);
3015 verify([source]); 3489 verify([source]);
3016 } 3490 }
3017 3491
3018 void test_nonConstValueInInitializer_binary_notInt() { 3492 void test_nonConstValueInInitializer_binary_notInt() {
3019 Source source = addSource(EngineTestCase.createSource([ 3493 Source source = addSource(r'''
3020 "class A {", 3494 class A {
3021 " final int a;", 3495 final int a;
3022 " const A(String p) : a = 5 & p;", 3496 const A(String p) : a = 5 & p;
3023 "}"])); 3497 }''');
3024 resolve(source); 3498 resolve(source);
3025 assertErrors(source, [ 3499 assertErrors(source, [
3026 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, 3500 CompileTimeErrorCode.CONST_EVAL_TYPE_INT,
3027 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 3501 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
3028 verify([source]); 3502 verify([source]);
3029 } 3503 }
3030 3504
3031 void test_nonConstValueInInitializer_binary_notNum() { 3505 void test_nonConstValueInInitializer_binary_notNum() {
3032 Source source = addSource(EngineTestCase.createSource([ 3506 Source source = addSource(r'''
3033 "class A {", 3507 class A {
3034 " final int a;", 3508 final int a;
3035 " const A(String p) : a = 5 + p;", 3509 const A(String p) : a = 5 + p;
3036 "}"])); 3510 }''');
3037 resolve(source); 3511 resolve(source);
3038 assertErrors(source, [ 3512 assertErrors(source, [
3039 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, 3513 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM,
3040 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 3514 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
3041 verify([source]); 3515 verify([source]);
3042 } 3516 }
3043 3517
3044 void test_nonConstValueInInitializer_field() { 3518 void test_nonConstValueInInitializer_field() {
3045 Source source = addSource(EngineTestCase.createSource([ 3519 Source source = addSource(r'''
3046 "class A {", 3520 class A {
3047 " static int C;", 3521 static int C;
3048 " final int a;", 3522 final int a;
3049 " const A() : a = C;", 3523 const A() : a = C;
3050 "}"])); 3524 }''');
3051 resolve(source); 3525 resolve(source);
3052 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER ]); 3526 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER ]);
3053 verify([source]); 3527 verify([source]);
3054 } 3528 }
3055 3529
3056 void test_nonConstValueInInitializer_instanceCreation() { 3530 void test_nonConstValueInInitializer_instanceCreation() {
3057 Source source = addSource(EngineTestCase.createSource([ 3531 Source source = addSource(r'''
3058 "class A {", 3532 class A {
3059 " A();", 3533 A();
3060 "}", 3534 }
3061 "class B {", 3535 class B {
3062 " const B() : a = new A();", 3536 const B() : a = new A();
3063 " final a;", 3537 final a;
3064 "}", 3538 }
3065 "var b = const B();"])); 3539 var b = const B();''');
3066 resolve(source); 3540 resolve(source);
3067 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER ]); 3541 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER ]);
3068 verify([source]); 3542 verify([source]);
3069 } 3543 }
3070 3544
3071 void test_nonConstValueInInitializer_redirecting() { 3545 void test_nonConstValueInInitializer_redirecting() {
3072 Source source = addSource(EngineTestCase.createSource([ 3546 Source source = addSource(r'''
3073 "class A {", 3547 class A {
3074 " static var C;", 3548 static var C;
3075 " const A.named(p);", 3549 const A.named(p);
3076 " const A() : this.named(C);", 3550 const A() : this.named(C);
3077 "}"])); 3551 }''');
3078 resolve(source); 3552 resolve(source);
3079 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER ]); 3553 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER ]);
3080 verify([source]); 3554 verify([source]);
3081 } 3555 }
3082 3556
3083 void test_nonConstValueInInitializer_super() { 3557 void test_nonConstValueInInitializer_super() {
3084 Source source = addSource(EngineTestCase.createSource([ 3558 Source source = addSource(r'''
3085 "class A {", 3559 class A {
3086 " const A(p);", 3560 const A(p);
3087 "}", 3561 }
3088 "class B extends A {", 3562 class B extends A {
3089 " static var C;", 3563 static var C;
3090 " const B() : super(C);", 3564 const B() : super(C);
3091 "}"])); 3565 }''');
3092 resolve(source); 3566 resolve(source);
3093 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER ]); 3567 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER ]);
3094 verify([source]); 3568 verify([source]);
3095 } 3569 }
3096 3570
3097 void test_nonConstValueInInitializerFromDeferredLibrary_field() { 3571 void test_nonConstValueInInitializerFromDeferredLibrary_field() {
3098 resolveWithAndWithoutExperimental(<String> [ 3572 resolveWithAndWithoutExperimental(<String> [
3099 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3573 r'''
3100 EngineTestCase.createSource([ 3574 library lib1;
3101 "library root;", 3575 const int c = 1;''',
3102 "import 'lib1.dart' deferred as a;", 3576 r'''
3103 "class A {", 3577 library root;
3104 " final int x;", 3578 import 'lib1.dart' deferred as a;
3105 " const A() : x = a.c;", 3579 class A {
3106 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_ LIBRARY]); 3580 final int x;
3581 const A() : x = a.c;
3582 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY]) ;
3107 } 3583 }
3108 3584
3109 void test_nonConstValueInInitializerFromDeferredLibrary_field_nested() { 3585 void test_nonConstValueInInitializerFromDeferredLibrary_field_nested() {
3110 resolveWithAndWithoutExperimental(<String> [ 3586 resolveWithAndWithoutExperimental(<String> [
3111 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3587 r'''
3112 EngineTestCase.createSource([ 3588 library lib1;
3113 "library root;", 3589 const int c = 1;''',
3114 "import 'lib1.dart' deferred as a;", 3590 r'''
3115 "class A {", 3591 library root;
3116 " final int x;", 3592 import 'lib1.dart' deferred as a;
3117 " const A() : x = a.c + 1;", 3593 class A {
3118 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_ LIBRARY]); 3594 final int x;
3595 const A() : x = a.c + 1;
3596 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY]) ;
3119 } 3597 }
3120 3598
3121 void test_nonConstValueInInitializerFromDeferredLibrary_redirecting() { 3599 void test_nonConstValueInInitializerFromDeferredLibrary_redirecting() {
3122 resolveWithAndWithoutExperimental(<String> [ 3600 resolveWithAndWithoutExperimental(<String> [
3123 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3601 r'''
3124 EngineTestCase.createSource([ 3602 library lib1;
3125 "library root;", 3603 const int c = 1;''',
3126 "import 'lib1.dart' deferred as a;", 3604 r'''
3127 "class A {", 3605 library root;
3128 " const A.named(p);", 3606 import 'lib1.dart' deferred as a;
3129 " const A() : this.named(a.c);", 3607 class A {
3130 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_ LIBRARY]); 3608 const A.named(p);
3609 const A() : this.named(a.c);
3610 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY]) ;
3131 } 3611 }
3132 3612
3133 void test_nonConstValueInInitializerFromDeferredLibrary_super() { 3613 void test_nonConstValueInInitializerFromDeferredLibrary_super() {
3134 resolveWithAndWithoutExperimental(<String> [ 3614 resolveWithAndWithoutExperimental(<String> [
3135 EngineTestCase.createSource(["library lib1;", "const int c = 1;"]), 3615 r'''
3136 EngineTestCase.createSource([ 3616 library lib1;
3137 "library root;", 3617 const int c = 1;''',
3138 "import 'lib1.dart' deferred as a;", 3618 r'''
3139 "class A {", 3619 library root;
3140 " const A(p);", 3620 import 'lib1.dart' deferred as a;
3141 "}", 3621 class A {
3142 "class B extends A {", 3622 const A(p);
3143 " const B() : super(a.c);", 3623 }
3144 "}"])], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <E rrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_ LIBRARY]); 3624 class B extends A {
3625 const B() : super(a.c);
3626 }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY]) ;
3145 } 3627 }
3146 3628
3147 void test_nonGenerativeConstructor_explicit() { 3629 void test_nonGenerativeConstructor_explicit() {
3148 Source source = addSource(EngineTestCase.createSource([ 3630 Source source = addSource(r'''
3149 "class A {", 3631 class A {
3150 " factory A.named() {}", 3632 factory A.named() {}
3151 "}", 3633 }
3152 "class B extends A {", 3634 class B extends A {
3153 " B() : super.named();", 3635 B() : super.named();
3154 "}"])); 3636 }''');
3155 resolve(source); 3637 resolve(source);
3156 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); 3638 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]);
3157 verify([source]); 3639 verify([source]);
3158 } 3640 }
3159 3641
3160 void test_nonGenerativeConstructor_implicit() { 3642 void test_nonGenerativeConstructor_implicit() {
3161 Source source = addSource(EngineTestCase.createSource([ 3643 Source source = addSource(r'''
3162 "class A {", 3644 class A {
3163 " factory A() {}", 3645 factory A() {}
3164 "}", 3646 }
3165 "class B extends A {", 3647 class B extends A {
3166 " B();", 3648 B();
3167 "}"])); 3649 }''');
3168 resolve(source); 3650 resolve(source);
3169 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); 3651 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]);
3170 verify([source]); 3652 verify([source]);
3171 } 3653 }
3172 3654
3173 void test_nonGenerativeConstructor_implicit2() { 3655 void test_nonGenerativeConstructor_implicit2() {
3174 Source source = addSource(EngineTestCase.createSource([ 3656 Source source = addSource(r'''
3175 "class A {", 3657 class A {
3176 " factory A() {}", 3658 factory A() {}
3177 "}", 3659 }
3178 "class B extends A {", 3660 class B extends A {
3179 "}"])); 3661 }''');
3180 resolve(source); 3662 resolve(source);
3181 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); 3663 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]);
3182 verify([source]); 3664 verify([source]);
3183 } 3665 }
3184 3666
3185 void test_notEnoughRequiredArguments_const() { 3667 void test_notEnoughRequiredArguments_const() {
3186 Source source = addSource(EngineTestCase.createSource([ 3668 Source source = addSource(r'''
3187 "class A {", 3669 class A {
3188 " const A(int p);", 3670 const A(int p);
3189 "}", 3671 }
3190 "main() {", 3672 main() {
3191 " const A();", 3673 const A();
3192 "}"])); 3674 }''');
3193 resolve(source); 3675 resolve(source);
3194 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); 3676 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]);
3195 verify([source]); 3677 verify([source]);
3196 } 3678 }
3197 3679
3198 void test_notEnoughRequiredArguments_const_super() { 3680 void test_notEnoughRequiredArguments_const_super() {
3199 Source source = addSource(EngineTestCase.createSource([ 3681 Source source = addSource(r'''
3200 "class A {", 3682 class A {
3201 " const A(int p);", 3683 const A(int p);
3202 "}", 3684 }
3203 "class B extends A {", 3685 class B extends A {
3204 " const B() : super();", 3686 const B() : super();
3205 "}"])); 3687 }''');
3206 resolve(source); 3688 resolve(source);
3207 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); 3689 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]);
3208 verify([source]); 3690 verify([source]);
3209 } 3691 }
3210 3692
3211 void test_optionalParameterInOperator_named() { 3693 void test_optionalParameterInOperator_named() {
3212 Source source = addSource(EngineTestCase.createSource(["class A {", " opera tor +({p}) {}", "}"])); 3694 Source source = addSource(r'''
3695 class A {
3696 operator +({p}) {}
3697 }''');
3213 resolve(source); 3698 resolve(source);
3214 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); 3699 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]);
3215 verify([source]); 3700 verify([source]);
3216 } 3701 }
3217 3702
3218 void test_optionalParameterInOperator_positional() { 3703 void test_optionalParameterInOperator_positional() {
3219 Source source = addSource(EngineTestCase.createSource(["class A {", " opera tor +([p]) {}", "}"])); 3704 Source source = addSource(r'''
3705 class A {
3706 operator +([p]) {}
3707 }''');
3220 resolve(source); 3708 resolve(source);
3221 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); 3709 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]);
3222 verify([source]); 3710 verify([source]);
3223 } 3711 }
3224 3712
3225 void test_partOfNonPart() { 3713 void test_partOfNonPart() {
3226 Source source = addSource(EngineTestCase.createSource(["library l1;", "part 'l2.dart';"])); 3714 Source source = addSource(r'''
3227 addNamedSource("/l2.dart", EngineTestCase.createSource(["library l2;"])); 3715 library l1;
3716 part 'l2.dart';''');
3717 addNamedSource("/l2.dart", "library l2;");
3228 resolve(source); 3718 resolve(source);
3229 assertErrors(source, [CompileTimeErrorCode.PART_OF_NON_PART]); 3719 assertErrors(source, [CompileTimeErrorCode.PART_OF_NON_PART]);
3230 verify([source]); 3720 verify([source]);
3231 } 3721 }
3232 3722
3233 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() { 3723 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() {
3234 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl ass A{}"])); 3724 addNamedSource("/lib.dart", r'''
3235 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "typedef p();", "p.A a;"])); 3725 library lib;
3726 class A{}''');
3727 Source source = addSource(r'''
3728 import 'lib.dart' as p;
3729 typedef p();
3730 p.A a;''');
3236 resolve(source); 3731 resolve(source);
3237 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME MBER]); 3732 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME MBER]);
3238 verify([source]); 3733 verify([source]);
3239 } 3734 }
3240 3735
3241 void test_prefixCollidesWithTopLevelMembers_topLevelFunction() { 3736 void test_prefixCollidesWithTopLevelMembers_topLevelFunction() {
3242 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl ass A{}"])); 3737 addNamedSource("/lib.dart", r'''
3243 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "p() {}", "p.A a;"])); 3738 library lib;
3739 class A{}''');
3740 Source source = addSource(r'''
3741 import 'lib.dart' as p;
3742 p() {}
3743 p.A a;''');
3244 resolve(source); 3744 resolve(source);
3245 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME MBER]); 3745 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME MBER]);
3246 verify([source]); 3746 verify([source]);
3247 } 3747 }
3248 3748
3249 void test_prefixCollidesWithTopLevelMembers_topLevelVariable() { 3749 void test_prefixCollidesWithTopLevelMembers_topLevelVariable() {
3250 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl ass A{}"])); 3750 addNamedSource("/lib.dart", r'''
3251 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "var p = null;", "p.A a;"])); 3751 library lib;
3752 class A{}''');
3753 Source source = addSource(r'''
3754 import 'lib.dart' as p;
3755 var p = null;
3756 p.A a;''');
3252 resolve(source); 3757 resolve(source);
3253 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME MBER]); 3758 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME MBER]);
3254 verify([source]); 3759 verify([source]);
3255 } 3760 }
3256 3761
3257 void test_prefixCollidesWithTopLevelMembers_type() { 3762 void test_prefixCollidesWithTopLevelMembers_type() {
3258 addNamedSource("/lib.dart", EngineTestCase.createSource(["library lib;", "cl ass A{}"])); 3763 addNamedSource("/lib.dart", r'''
3259 Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "class p {}", "p.A a;"])); 3764 library lib;
3765 class A{}''');
3766 Source source = addSource(r'''
3767 import 'lib.dart' as p;
3768 class p {}
3769 p.A a;''');
3260 resolve(source); 3770 resolve(source);
3261 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME MBER]); 3771 assertErrors(source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_ME MBER]);
3262 verify([source]); 3772 verify([source]);
3263 } 3773 }
3264 3774
3265 void test_privateOptionalParameter() { 3775 void test_privateOptionalParameter() {
3266 Source source = addSource(EngineTestCase.createSource(["f({var _p}) {}"])); 3776 Source source = addSource("f({var _p}) {}");
3267 resolve(source); 3777 resolve(source);
3268 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); 3778 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]);
3269 verify([source]); 3779 verify([source]);
3270 } 3780 }
3271 3781
3272 void test_privateOptionalParameter_fieldFormal() { 3782 void test_privateOptionalParameter_fieldFormal() {
3273 Source source = addSource(EngineTestCase.createSource(["class A {", " var _ p;", " A({this._p: 0});", "}"])); 3783 Source source = addSource(r'''
3784 class A {
3785 var _p;
3786 A({this._p: 0});
3787 }''');
3274 resolve(source); 3788 resolve(source);
3275 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); 3789 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]);
3276 verify([source]); 3790 verify([source]);
3277 } 3791 }
3278 3792
3279 void test_privateOptionalParameter_withDefaultValue() { 3793 void test_privateOptionalParameter_withDefaultValue() {
3280 Source source = addSource(EngineTestCase.createSource(["f({_p : 0}) {}"])); 3794 Source source = addSource("f({_p : 0}) {}");
3281 resolve(source); 3795 resolve(source);
3282 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); 3796 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]);
3283 verify([source]); 3797 verify([source]);
3284 } 3798 }
3285 3799
3286 void test_recursiveConstructorRedirect() { 3800 void test_recursiveConstructorRedirect() {
3287 Source source = addSource(EngineTestCase.createSource([ 3801 Source source = addSource(r'''
3288 "class A {", 3802 class A {
3289 " A.a() : this.b();", 3803 A.a() : this.b();
3290 " A.b() : this.a();", 3804 A.b() : this.a();
3291 "}"])); 3805 }''');
3292 resolve(source); 3806 resolve(source);
3293 assertErrors(source, [ 3807 assertErrors(source, [
3294 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT, 3808 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT,
3295 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]); 3809 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]);
3296 verify([source]); 3810 verify([source]);
3297 } 3811 }
3298 3812
3299 void test_recursiveConstructorRedirect_directSelfReference() { 3813 void test_recursiveConstructorRedirect_directSelfReference() {
3300 Source source = addSource(EngineTestCase.createSource(["class A {", " A() : this();", "}"])); 3814 Source source = addSource(r'''
3815 class A {
3816 A() : this();
3817 }''');
3301 resolve(source); 3818 resolve(source);
3302 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]); 3819 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]);
3303 verify([source]); 3820 verify([source]);
3304 } 3821 }
3305 3822
3306 void test_recursiveFactoryRedirect() { 3823 void test_recursiveFactoryRedirect() {
3307 Source source = addSource(EngineTestCase.createSource([ 3824 Source source = addSource(r'''
3308 "class A implements B {", 3825 class A implements B {
3309 " factory A() = C;", 3826 factory A() = C;
3310 "}", 3827 }
3311 "class B implements C {", 3828 class B implements C {
3312 " factory B() = A;", 3829 factory B() = A;
3313 "}", 3830 }
3314 "class C implements A {", 3831 class C implements A {
3315 " factory C() = B;", 3832 factory C() = B;
3316 "}"])); 3833 }''');
3317 resolve(source); 3834 resolve(source);
3318 assertErrors(source, [ 3835 assertErrors(source, [
3319 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3836 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3320 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3837 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3321 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3838 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3322 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3839 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3323 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3840 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3324 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3841 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3325 verify([source]); 3842 verify([source]);
3326 } 3843 }
3327 3844
3328 void test_recursiveFactoryRedirect_directSelfReference() { 3845 void test_recursiveFactoryRedirect_directSelfReference() {
3329 Source source = addSource(EngineTestCase.createSource(["class A {", " facto ry A() = A;", "}"])); 3846 Source source = addSource(r'''
3847 class A {
3848 factory A() = A;
3849 }''');
3330 resolve(source); 3850 resolve(source);
3331 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); 3851 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]);
3332 verify([source]); 3852 verify([source]);
3333 } 3853 }
3334 3854
3335 void test_recursiveFactoryRedirect_generic() { 3855 void test_recursiveFactoryRedirect_generic() {
3336 Source source = addSource(EngineTestCase.createSource([ 3856 Source source = addSource(r'''
3337 "class A<T> implements B<T> {", 3857 class A<T> implements B<T> {
3338 " factory A() = C;", 3858 factory A() = C;
3339 "}", 3859 }
3340 "class B<T> implements C<T> {", 3860 class B<T> implements C<T> {
3341 " factory B() = A;", 3861 factory B() = A;
3342 "}", 3862 }
3343 "class C<T> implements A<T> {", 3863 class C<T> implements A<T> {
3344 " factory C() = B;", 3864 factory C() = B;
3345 "}"])); 3865 }''');
3346 resolve(source); 3866 resolve(source);
3347 assertErrors(source, [ 3867 assertErrors(source, [
3348 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3868 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3349 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3869 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3350 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3870 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3351 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3871 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3352 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3872 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3353 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3873 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3354 verify([source]); 3874 verify([source]);
3355 } 3875 }
3356 3876
3357 void test_recursiveFactoryRedirect_named() { 3877 void test_recursiveFactoryRedirect_named() {
3358 Source source = addSource(EngineTestCase.createSource([ 3878 Source source = addSource(r'''
3359 "class A implements B {", 3879 class A implements B {
3360 " factory A.nameA() = C.nameC;", 3880 factory A.nameA() = C.nameC;
3361 "}", 3881 }
3362 "class B implements C {", 3882 class B implements C {
3363 " factory B.nameB() = A.nameA;", 3883 factory B.nameB() = A.nameA;
3364 "}", 3884 }
3365 "class C implements A {", 3885 class C implements A {
3366 " factory C.nameC() = B.nameB;", 3886 factory C.nameC() = B.nameB;
3367 "}"])); 3887 }''');
3368 resolve(source); 3888 resolve(source);
3369 assertErrors(source, [ 3889 assertErrors(source, [
3370 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3890 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3371 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3891 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3372 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3892 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3373 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3893 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3374 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3894 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3375 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3895 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3376 verify([source]); 3896 verify([source]);
3377 } 3897 }
3378 3898
3379 /** 3899 /**
3380 * "A" references "C" which has cycle with "B". But we should not report probl em for "A" - it is 3900 * "A" references "C" which has cycle with "B". But we should not report probl em for "A" - it is
3381 * not the part of a cycle. 3901 * not the part of a cycle.
3382 */ 3902 */
3383 void test_recursiveFactoryRedirect_outsideCycle() { 3903 void test_recursiveFactoryRedirect_outsideCycle() {
3384 Source source = addSource(EngineTestCase.createSource([ 3904 Source source = addSource(r'''
3385 "class A {", 3905 class A {
3386 " factory A() = C;", 3906 factory A() = C;
3387 "}", 3907 }
3388 "class B implements C {", 3908 class B implements C {
3389 " factory B() = C;", 3909 factory B() = C;
3390 "}", 3910 }
3391 "class C implements A, B {", 3911 class C implements A, B {
3392 " factory C() = B;", 3912 factory C() = B;
3393 "}"])); 3913 }''');
3394 resolve(source); 3914 resolve(source);
3395 assertErrors(source, [ 3915 assertErrors(source, [
3396 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3916 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3397 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 3917 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
3398 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3918 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3399 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3919 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3400 verify([source]); 3920 verify([source]);
3401 } 3921 }
3402 3922
3403 void test_recursiveInterfaceInheritance_extends() { 3923 void test_recursiveInterfaceInheritance_extends() {
3404 Source source = addSource(EngineTestCase.createSource(["class A extends B {} ", "class B extends A {}"])); 3924 Source source = addSource(r'''
3925 class A extends B {}
3926 class B extends A {}''');
3405 resolve(source); 3927 resolve(source);
3406 assertErrors(source, [ 3928 assertErrors(source, [
3407 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3929 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3408 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3930 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3409 verify([source]); 3931 verify([source]);
3410 } 3932 }
3411 3933
3412 void test_recursiveInterfaceInheritance_extends_implements() { 3934 void test_recursiveInterfaceInheritance_extends_implements() {
3413 Source source = addSource(EngineTestCase.createSource(["class A extends B {} ", "class B implements A {}"])); 3935 Source source = addSource(r'''
3936 class A extends B {}
3937 class B implements A {}''');
3414 resolve(source); 3938 resolve(source);
3415 assertErrors(source, [ 3939 assertErrors(source, [
3416 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3940 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3417 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3941 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3418 verify([source]); 3942 verify([source]);
3419 } 3943 }
3420 3944
3421 void test_recursiveInterfaceInheritance_implements() { 3945 void test_recursiveInterfaceInheritance_implements() {
3422 Source source = addSource(EngineTestCase.createSource(["class A implements B {}", "class B implements A {}"])); 3946 Source source = addSource(r'''
3947 class A implements B {}
3948 class B implements A {}''');
3423 resolve(source); 3949 resolve(source);
3424 assertErrors(source, [ 3950 assertErrors(source, [
3425 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3951 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3426 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3952 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3427 verify([source]); 3953 verify([source]);
3428 } 3954 }
3429 3955
3430 void test_recursiveInterfaceInheritance_mixin() { 3956 void test_recursiveInterfaceInheritance_mixin() {
3431 Source source = addSource(EngineTestCase.createSource([ 3957 Source source = addSource(r'''
3432 "class M1 = Object with M2;", 3958 class M1 = Object with M2;
3433 "class M2 = Object with M1;"])); 3959 class M2 = Object with M1;''');
3434 resolve(source); 3960 resolve(source);
3435 assertErrors(source, [ 3961 assertErrors(source, [
3436 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3962 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3437 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3963 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3438 verify([source]); 3964 verify([source]);
3439 } 3965 }
3440 3966
3441 void test_recursiveInterfaceInheritance_tail() { 3967 void test_recursiveInterfaceInheritance_tail() {
3442 Source source = addSource(EngineTestCase.createSource([ 3968 Source source = addSource(r'''
3443 "abstract class A implements A {}", 3969 abstract class A implements A {}
3444 "class B implements A {}"])); 3970 class B implements A {}''');
3445 resolve(source); 3971 resolve(source);
3446 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_IMPLEMENTS]); 3972 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_IMPLEMENTS]);
3447 verify([source]); 3973 verify([source]);
3448 } 3974 }
3449 3975
3450 void test_recursiveInterfaceInheritance_tail2() { 3976 void test_recursiveInterfaceInheritance_tail2() {
3451 Source source = addSource(EngineTestCase.createSource([ 3977 Source source = addSource(r'''
3452 "abstract class A implements B {}", 3978 abstract class A implements B {}
3453 "abstract class B implements A {}", 3979 abstract class B implements A {}
3454 "class C implements A {}"])); 3980 class C implements A {}''');
3455 resolve(source); 3981 resolve(source);
3456 assertErrors(source, [ 3982 assertErrors(source, [
3457 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3983 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3458 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3984 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3459 verify([source]); 3985 verify([source]);
3460 } 3986 }
3461 3987
3462 void test_recursiveInterfaceInheritance_tail3() { 3988 void test_recursiveInterfaceInheritance_tail3() {
3463 Source source = addSource(EngineTestCase.createSource([ 3989 Source source = addSource(r'''
3464 "abstract class A implements B {}", 3990 abstract class A implements B {}
3465 "abstract class B implements C {}", 3991 abstract class B implements C {}
3466 "abstract class C implements A {}", 3992 abstract class C implements A {}
3467 "class D implements A {}"])); 3993 class D implements A {}''');
3468 resolve(source); 3994 resolve(source);
3469 assertErrors(source, [ 3995 assertErrors(source, [
3470 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3996 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3471 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 3997 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
3472 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]); 3998 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
3473 verify([source]); 3999 verify([source]);
3474 } 4000 }
3475 4001
3476 void test_recursiveInterfaceInheritanceBaseCaseExtends() { 4002 void test_recursiveInterfaceInheritanceBaseCaseExtends() {
3477 Source source = addSource(EngineTestCase.createSource(["class A extends A {} "])); 4003 Source source = addSource("class A extends A {}");
3478 resolve(source); 4004 resolve(source);
3479 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_EXTENDS]); 4005 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_EXTENDS]);
3480 verify([source]); 4006 verify([source]);
3481 } 4007 }
3482 4008
3483 void test_recursiveInterfaceInheritanceBaseCaseImplements() { 4009 void test_recursiveInterfaceInheritanceBaseCaseImplements() {
3484 Source source = addSource(EngineTestCase.createSource(["class A implements A {}"])); 4010 Source source = addSource("class A implements A {}");
3485 resolve(source); 4011 resolve(source);
3486 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_IMPLEMENTS]); 4012 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_IMPLEMENTS]);
3487 verify([source]); 4013 verify([source]);
3488 } 4014 }
3489 4015
3490 void test_recursiveInterfaceInheritanceBaseCaseImplements_typeAlias() { 4016 void test_recursiveInterfaceInheritanceBaseCaseImplements_typeAlias() {
3491 Source source = addSource(EngineTestCase.createSource([ 4017 Source source = addSource(r'''
3492 "class A {}", 4018 class A {}
3493 "class M {}", 4019 class M {}
3494 "class B = A with M implements B;"])); 4020 class B = A with M implements B;''');
3495 resolve(source); 4021 resolve(source);
3496 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_IMPLEMENTS]); 4022 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_IMPLEMENTS]);
3497 verify([source]); 4023 verify([source]);
3498 } 4024 }
3499 4025
3500 void test_recursiveInterfaceInheritanceBaseCaseWith() { 4026 void test_recursiveInterfaceInheritanceBaseCaseWith() {
3501 Source source = addSource(EngineTestCase.createSource(["class M = Object wit h M;"])); 4027 Source source = addSource("class M = Object with M;");
3502 resolve(source); 4028 resolve(source);
3503 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_WITH]); 4029 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_B ASE_CASE_WITH]);
3504 verify([source]); 4030 verify([source]);
3505 } 4031 }
3506 4032
3507 void test_redirectGenerativeToMissingConstructor() { 4033 void test_redirectGenerativeToMissingConstructor() {
3508 Source source = addSource(EngineTestCase.createSource(["class A {", " A() : this.noSuchConstructor();", "}"])); 4034 Source source = addSource(r'''
4035 class A {
4036 A() : this.noSuchConstructor();
4037 }''');
3509 resolve(source); 4038 resolve(source);
3510 assertErrors(source, [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CO NSTRUCTOR]); 4039 assertErrors(source, [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CO NSTRUCTOR]);
3511 } 4040 }
3512 4041
3513 void test_redirectGenerativeToNonGenerativeConstructor() { 4042 void test_redirectGenerativeToNonGenerativeConstructor() {
3514 Source source = addSource(EngineTestCase.createSource([ 4043 Source source = addSource(r'''
3515 "class A {", 4044 class A {
3516 " A() : this.x();", 4045 A() : this.x();
3517 " factory A.x() => null;", 4046 factory A.x() => null;
3518 "}"])); 4047 }''');
3519 resolve(source); 4048 resolve(source);
3520 assertErrors(source, [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERA TIVE_CONSTRUCTOR]); 4049 assertErrors(source, [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERA TIVE_CONSTRUCTOR]);
3521 verify([source]); 4050 verify([source]);
3522 } 4051 }
3523 4052
3524 void test_redirectToMissingConstructor_named() { 4053 void test_redirectToMissingConstructor_named() {
3525 Source source = addSource(EngineTestCase.createSource([ 4054 Source source = addSource(r'''
3526 "class A implements B{", 4055 class A implements B{
3527 " A() {}", 4056 A() {}
3528 "}", 4057 }
3529 "class B {", 4058 class B {
3530 " const factory B() = A.name;", 4059 const factory B() = A.name;
3531 "}"])); 4060 }''');
3532 resolve(source); 4061 resolve(source);
3533 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]) ; 4062 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]) ;
3534 } 4063 }
3535 4064
3536 void test_redirectToMissingConstructor_unnamed() { 4065 void test_redirectToMissingConstructor_unnamed() {
3537 Source source = addSource(EngineTestCase.createSource([ 4066 Source source = addSource(r'''
3538 "class A implements B{", 4067 class A implements B{
3539 " A.name() {}", 4068 A.name() {}
3540 "}", 4069 }
3541 "class B {", 4070 class B {
3542 " const factory B() = A;", 4071 const factory B() = A;
3543 "}"])); 4072 }''');
3544 resolve(source); 4073 resolve(source);
3545 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]) ; 4074 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]) ;
3546 } 4075 }
3547 4076
3548 void test_redirectToNonClass_notAType() { 4077 void test_redirectToNonClass_notAType() {
3549 Source source = addSource(EngineTestCase.createSource(["int A;", "class B {" , " const factory B() = A;", "}"])); 4078 Source source = addSource(r'''
4079 int A;
4080 class B {
4081 const factory B() = A;
4082 }''');
3550 resolve(source); 4083 resolve(source);
3551 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); 4084 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]);
3552 verify([source]); 4085 verify([source]);
3553 } 4086 }
3554 4087
3555 void test_redirectToNonClass_undefinedIdentifier() { 4088 void test_redirectToNonClass_undefinedIdentifier() {
3556 Source source = addSource(EngineTestCase.createSource(["class B {", " const factory B() = A;", "}"])); 4089 Source source = addSource(r'''
4090 class B {
4091 const factory B() = A;
4092 }''');
3557 resolve(source); 4093 resolve(source);
3558 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); 4094 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]);
3559 verify([source]); 4095 verify([source]);
3560 } 4096 }
3561 4097
3562 void test_redirectToNonConstConstructor() { 4098 void test_redirectToNonConstConstructor() {
3563 Source source = addSource(EngineTestCase.createSource([ 4099 Source source = addSource(r'''
3564 "class A {", 4100 class A {
3565 " A.a() {}", 4101 A.a() {}
3566 " const factory A.b() = A.a;", 4102 const factory A.b() = A.a;
3567 "}"])); 4103 }''');
3568 resolve(source); 4104 resolve(source);
3569 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR ]); 4105 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR ]);
3570 verify([source]); 4106 verify([source]);
3571 } 4107 }
3572 4108
3573 void test_referencedBeforeDeclaration_hideInBlock_function() { 4109 void test_referencedBeforeDeclaration_hideInBlock_function() {
3574 Source source = addSource(EngineTestCase.createSource([ 4110 Source source = addSource(r'''
3575 "var v = 1;", 4111 var v = 1;
3576 "main() {", 4112 main() {
3577 " print(v);", 4113 print(v);
3578 " v() {}", 4114 v() {}
3579 "}", 4115 }
3580 "print(x) {}"])); 4116 print(x) {}''');
3581 resolve(source); 4117 resolve(source);
3582 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 4118 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
3583 } 4119 }
3584 4120
3585 void test_referencedBeforeDeclaration_hideInBlock_local() { 4121 void test_referencedBeforeDeclaration_hideInBlock_local() {
3586 Source source = addSource(EngineTestCase.createSource([ 4122 Source source = addSource(r'''
3587 "var v = 1;", 4123 var v = 1;
3588 "main() {", 4124 main() {
3589 " print(v);", 4125 print(v);
3590 " var v = 2;", 4126 var v = 2;
3591 "}", 4127 }
3592 "print(x) {}"])); 4128 print(x) {}''');
3593 resolve(source); 4129 resolve(source);
3594 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 4130 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
3595 } 4131 }
3596 4132
3597 void test_referencedBeforeDeclaration_hideInBlock_subBlock() { 4133 void test_referencedBeforeDeclaration_hideInBlock_subBlock() {
3598 Source source = addSource(EngineTestCase.createSource([ 4134 Source source = addSource(r'''
3599 "var v = 1;", 4135 var v = 1;
3600 "main() {", 4136 main() {
3601 " {", 4137 {
3602 " print(v);", 4138 print(v);
3603 " }", 4139 }
3604 " var v = 2;", 4140 var v = 2;
3605 "}", 4141 }
3606 "print(x) {}"])); 4142 print(x) {}''');
3607 resolve(source); 4143 resolve(source);
3608 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 4144 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
3609 } 4145 }
3610 4146
3611 void test_referencedBeforeDeclaration_inInitializer_closure() { 4147 void test_referencedBeforeDeclaration_inInitializer_closure() {
3612 Source source = addSource(EngineTestCase.createSource(["main() {", " var v = () => v;", "}"])); 4148 Source source = addSource(r'''
4149 main() {
4150 var v = () => v;
4151 }''');
3613 resolve(source); 4152 resolve(source);
3614 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 4153 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
3615 } 4154 }
3616 4155
3617 void test_referencedBeforeDeclaration_inInitializer_directly() { 4156 void test_referencedBeforeDeclaration_inInitializer_directly() {
3618 Source source = addSource(EngineTestCase.createSource(["main() {", " var v = v;", "}"])); 4157 Source source = addSource(r'''
4158 main() {
4159 var v = v;
4160 }''');
3619 resolve(source); 4161 resolve(source);
3620 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 4162 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
3621 } 4163 }
3622 4164
3623 void test_rethrowOutsideCatch() { 4165 void test_rethrowOutsideCatch() {
3624 Source source = addSource(EngineTestCase.createSource(["f() {", " rethrow;" , "}"])); 4166 Source source = addSource(r'''
4167 f() {
4168 rethrow;
4169 }''');
3625 resolve(source); 4170 resolve(source);
3626 assertErrors(source, [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]); 4171 assertErrors(source, [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]);
3627 verify([source]); 4172 verify([source]);
3628 } 4173 }
3629 4174
3630 void test_returnInGenerativeConstructor() { 4175 void test_returnInGenerativeConstructor() {
3631 Source source = addSource(EngineTestCase.createSource(["class A {", " A() { return 0; }", "}"])); 4176 Source source = addSource(r'''
4177 class A {
4178 A() { return 0; }
4179 }''');
3632 resolve(source); 4180 resolve(source);
3633 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR] ); 4181 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR] );
3634 verify([source]); 4182 verify([source]);
3635 } 4183 }
3636 4184
3637 void test_returnInGenerativeConstructor_expressionFunctionBody() { 4185 void test_returnInGenerativeConstructor_expressionFunctionBody() {
3638 Source source = addSource(EngineTestCase.createSource(["class A {", " A() = > null;", "}"])); 4186 Source source = addSource(r'''
4187 class A {
4188 A() => null;
4189 }''');
3639 resolve(source); 4190 resolve(source);
3640 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR] ); 4191 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR] );
3641 verify([source]); 4192 verify([source]);
3642 } 4193 }
3643 4194
3644 void test_returnInGenerator_asyncStar() { 4195 void test_returnInGenerator_asyncStar() {
3645 resetWithAsync(); 4196 resetWithAsync();
3646 Source source = addSource(EngineTestCase.createSource(["f() async* {", " re turn 0;", "}"])); 4197 Source source = addSource(r'''
4198 f() async* {
4199 return 0;
4200 }''');
3647 resolve(source); 4201 resolve(source);
3648 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); 4202 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]);
3649 verify([source]); 4203 verify([source]);
3650 } 4204 }
3651 4205
3652 void test_returnInGenerator_syncStar() { 4206 void test_returnInGenerator_syncStar() {
3653 resetWithAsync(); 4207 resetWithAsync();
3654 Source source = addSource(EngineTestCase.createSource(["f() sync* {", " ret urn 0;", "}"])); 4208 Source source = addSource(r'''
4209 f() sync* {
4210 return 0;
4211 }''');
3655 resolve(source); 4212 resolve(source);
3656 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); 4213 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]);
3657 verify([source]); 4214 verify([source]);
3658 } 4215 }
3659 4216
3660 void test_sharedDeferredPrefix() { 4217 void test_sharedDeferredPrefix() {
3661 resolveWithAndWithoutExperimental(<String> [ 4218 resolveWithAndWithoutExperimental(<String> [
3662 EngineTestCase.createSource(["library lib1;", "f1() {}"]), 4219 r'''
3663 EngineTestCase.createSource(["library lib2;", "f2() {}"]), 4220 library lib1;
3664 EngineTestCase.createSource([ 4221 f1() {}''',
3665 "library root;", 4222 r'''
3666 "import 'lib1.dart' deferred as lib;", 4223 library lib2;
3667 "import 'lib2.dart' as lib;", 4224 f2() {}''',
3668 "main() { lib.f1(); lib.f2(); }"])], <ErrorCode> [ParserErrorCode.DEFERR ED_IMPORTS_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.SHARED_DEFERRED_PRE FIX]); 4225 r'''
4226 library root;
4227 import 'lib1.dart' deferred as lib;
4228 import 'lib2.dart' as lib;
4229 main() { lib.f1(); lib.f2(); }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORT S_NOT_SUPPORTED], <ErrorCode> [CompileTimeErrorCode.SHARED_DEFERRED_PREFIX]);
3669 } 4230 }
3670 4231
3671 void test_superInInvalidContext_binaryExpression() { 4232 void test_superInInvalidContext_binaryExpression() {
3672 Source source = addSource(EngineTestCase.createSource(["var v = super + 0;"] )); 4233 Source source = addSource("var v = super + 0;");
3673 resolve(source); 4234 resolve(source);
3674 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 4235 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
3675 // no verify(), 'super.v' is not resolved 4236 // no verify(), 'super.v' is not resolved
3676 } 4237 }
3677 4238
3678 void test_superInInvalidContext_constructorFieldInitializer() { 4239 void test_superInInvalidContext_constructorFieldInitializer() {
3679 Source source = addSource(EngineTestCase.createSource([ 4240 Source source = addSource(r'''
3680 "class A {", 4241 class A {
3681 " m() {}", 4242 m() {}
3682 "}", 4243 }
3683 "class B extends A {", 4244 class B extends A {
3684 " var f;", 4245 var f;
3685 " B() : f = super.m();", 4246 B() : f = super.m();
3686 "}"])); 4247 }''');
3687 resolve(source); 4248 resolve(source);
3688 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 4249 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
3689 // no verify(), 'super.m' is not resolved 4250 // no verify(), 'super.m' is not resolved
3690 } 4251 }
3691 4252
3692 void test_superInInvalidContext_factoryConstructor() { 4253 void test_superInInvalidContext_factoryConstructor() {
3693 Source source = addSource(EngineTestCase.createSource([ 4254 Source source = addSource(r'''
3694 "class A {", 4255 class A {
3695 " m() {}", 4256 m() {}
3696 "}", 4257 }
3697 "class B extends A {", 4258 class B extends A {
3698 " factory B() {", 4259 factory B() {
3699 " super.m();", 4260 super.m();
3700 " }", 4261 }
3701 "}"])); 4262 }''');
3702 resolve(source); 4263 resolve(source);
3703 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 4264 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
3704 // no verify(), 'super.m' is not resolved 4265 // no verify(), 'super.m' is not resolved
3705 } 4266 }
3706 4267
3707 void test_superInInvalidContext_instanceVariableInitializer() { 4268 void test_superInInvalidContext_instanceVariableInitializer() {
3708 Source source = addSource(EngineTestCase.createSource([ 4269 Source source = addSource(r'''
3709 "class A {", 4270 class A {
3710 " var a;", 4271 var a;
3711 "}", 4272 }
3712 "class B extends A {", 4273 class B extends A {
3713 " var b = super.a;", 4274 var b = super.a;
3714 "}"])); 4275 }''');
3715 resolve(source); 4276 resolve(source);
3716 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 4277 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
3717 // no verify(), 'super.a' is not resolved 4278 // no verify(), 'super.a' is not resolved
3718 } 4279 }
3719 4280
3720 void test_superInInvalidContext_staticMethod() { 4281 void test_superInInvalidContext_staticMethod() {
3721 Source source = addSource(EngineTestCase.createSource([ 4282 Source source = addSource(r'''
3722 "class A {", 4283 class A {
3723 " static m() {}", 4284 static m() {}
3724 "}", 4285 }
3725 "class B extends A {", 4286 class B extends A {
3726 " static n() { return super.m(); }", 4287 static n() { return super.m(); }
3727 "}"])); 4288 }''');
3728 resolve(source); 4289 resolve(source);
3729 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 4290 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
3730 // no verify(), 'super.m' is not resolved 4291 // no verify(), 'super.m' is not resolved
3731 } 4292 }
3732 4293
3733 void test_superInInvalidContext_staticVariableInitializer() { 4294 void test_superInInvalidContext_staticVariableInitializer() {
3734 Source source = addSource(EngineTestCase.createSource([ 4295 Source source = addSource(r'''
3735 "class A {", 4296 class A {
3736 " static int a = 0;", 4297 static int a = 0;
3737 "}", 4298 }
3738 "class B extends A {", 4299 class B extends A {
3739 " static int b = super.a;", 4300 static int b = super.a;
3740 "}"])); 4301 }''');
3741 resolve(source); 4302 resolve(source);
3742 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 4303 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
3743 // no verify(), 'super.a' is not resolved 4304 // no verify(), 'super.a' is not resolved
3744 } 4305 }
3745 4306
3746 void test_superInInvalidContext_topLevelFunction() { 4307 void test_superInInvalidContext_topLevelFunction() {
3747 Source source = addSource(EngineTestCase.createSource(["f() {", " super.f() ;", "}"])); 4308 Source source = addSource(r'''
4309 f() {
4310 super.f();
4311 }''');
3748 resolve(source); 4312 resolve(source);
3749 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 4313 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
3750 // no verify(), 'super.f' is not resolved 4314 // no verify(), 'super.f' is not resolved
3751 } 4315 }
3752 4316
3753 void test_superInInvalidContext_topLevelVariableInitializer() { 4317 void test_superInInvalidContext_topLevelVariableInitializer() {
3754 Source source = addSource(EngineTestCase.createSource(["var v = super.y;"])) ; 4318 Source source = addSource("var v = super.y;");
3755 resolve(source); 4319 resolve(source);
3756 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 4320 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
3757 // no verify(), 'super.y' is not resolved 4321 // no verify(), 'super.y' is not resolved
3758 } 4322 }
3759 4323
3760 void test_superInRedirectingConstructor_redirectionSuper() { 4324 void test_superInRedirectingConstructor_redirectionSuper() {
3761 Source source = addSource(EngineTestCase.createSource([ 4325 Source source = addSource(r'''
3762 "class A {}", 4326 class A {}
3763 "class B {", 4327 class B {
3764 " B() : this.name(), super();", 4328 B() : this.name(), super();
3765 " B.name() {}", 4329 B.name() {}
3766 "}"])); 4330 }''');
3767 resolve(source); 4331 resolve(source);
3768 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR] ); 4332 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR] );
3769 verify([source]); 4333 verify([source]);
3770 } 4334 }
3771 4335
3772 void test_superInRedirectingConstructor_superRedirection() { 4336 void test_superInRedirectingConstructor_superRedirection() {
3773 Source source = addSource(EngineTestCase.createSource([ 4337 Source source = addSource(r'''
3774 "class A {}", 4338 class A {}
3775 "class B {", 4339 class B {
3776 " B() : super(), this.name();", 4340 B() : super(), this.name();
3777 " B.name() {}", 4341 B.name() {}
3778 "}"])); 4342 }''');
3779 resolve(source); 4343 resolve(source);
3780 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR] ); 4344 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR] );
3781 verify([source]); 4345 verify([source]);
3782 } 4346 }
3783 4347
3784 void test_symbol_constructor_badArgs() { 4348 void test_symbol_constructor_badArgs() {
3785 Source source = addSource(EngineTestCase.createSource([ 4349 Source source = addSource(r'''
3786 "var s1 = const Symbol('3');", 4350 var s1 = const Symbol('3');
3787 "var s2 = const Symbol(3);", 4351 var s2 = const Symbol(3);
3788 "var s3 = const Symbol();", 4352 var s3 = const Symbol();
3789 "var s4 = const Symbol('x', 'y');", 4353 var s4 = const Symbol('x', 'y');
3790 "var s5 = const Symbol('x', foo: 'x');"])); 4354 var s5 = const Symbol('x', foo: 'x');''');
3791 resolve(source); 4355 resolve(source);
3792 assertErrors(source, [ 4356 assertErrors(source, [
3793 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 4357 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
3794 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 4358 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
3795 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 4359 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
3796 CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS, 4360 CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS,
3797 CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 4361 CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS,
3798 CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]); 4362 CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]);
3799 verify([source]); 4363 verify([source]);
3800 } 4364 }
3801 4365
3802 void test_typeAliasCannotReferenceItself_11987() { 4366 void test_typeAliasCannotReferenceItself_11987() {
3803 Source source = addSource(EngineTestCase.createSource([ 4367 Source source = addSource(r'''
3804 "typedef void F(List<G> l);", 4368 typedef void F(List<G> l);
3805 "typedef void G(List<F> l);", 4369 typedef void G(List<F> l);
3806 "main() {", 4370 main() {
3807 " F foo(G g) => g;", 4371 F foo(G g) => g;
3808 "}"])); 4372 }''');
3809 resolve(source); 4373 resolve(source);
3810 assertErrors(source, [ 4374 assertErrors(source, [
3811 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 4375 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF,
3812 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 4376 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF,
3813 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); 4377 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
3814 verify([source]); 4378 verify([source]);
3815 } 4379 }
3816 4380
3817 void test_typeAliasCannotReferenceItself_parameterType_named() { 4381 void test_typeAliasCannotReferenceItself_parameterType_named() {
3818 Source source = addSource(EngineTestCase.createSource(["typedef A({A a});"]) ); 4382 Source source = addSource("typedef A({A a});");
3819 resolve(source); 4383 resolve(source);
3820 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]); 4384 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]);
3821 verify([source]); 4385 verify([source]);
3822 } 4386 }
3823 4387
3824 void test_typeAliasCannotReferenceItself_parameterType_positional() { 4388 void test_typeAliasCannotReferenceItself_parameterType_positional() {
3825 Source source = addSource(EngineTestCase.createSource(["typedef A([A a]);"]) ); 4389 Source source = addSource("typedef A([A a]);");
3826 resolve(source); 4390 resolve(source);
3827 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]); 4391 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]);
3828 verify([source]); 4392 verify([source]);
3829 } 4393 }
3830 4394
3831 void test_typeAliasCannotReferenceItself_parameterType_required() { 4395 void test_typeAliasCannotReferenceItself_parameterType_required() {
3832 Source source = addSource(EngineTestCase.createSource(["typedef A(A a);"])); 4396 Source source = addSource("typedef A(A a);");
3833 resolve(source); 4397 resolve(source);
3834 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]); 4398 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]);
3835 verify([source]); 4399 verify([source]);
3836 } 4400 }
3837 4401
3838 void test_typeAliasCannotReferenceItself_parameterType_typeArgument() { 4402 void test_typeAliasCannotReferenceItself_parameterType_typeArgument() {
3839 Source source = addSource(EngineTestCase.createSource(["typedef A(List<A> a) ;"])); 4403 Source source = addSource("typedef A(List<A> a);");
3840 resolve(source); 4404 resolve(source);
3841 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]); 4405 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]);
3842 verify([source]); 4406 verify([source]);
3843 } 4407 }
3844 4408
3845 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() { 4409 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() {
3846 Source source = addSource(EngineTestCase.createSource([ 4410 Source source = addSource(r'''
3847 "typedef C A();", 4411 typedef C A();
3848 "typedef A B();", 4412 typedef A B();
3849 "class C {", 4413 class C {
3850 " B a;", 4414 B a;
3851 "}"])); 4415 }''');
3852 resolve(source); 4416 resolve(source);
3853 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]); 4417 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]);
3854 verify([source]); 4418 verify([source]);
3855 } 4419 }
3856 4420
3857 void test_typeAliasCannotReferenceItself_returnType() { 4421 void test_typeAliasCannotReferenceItself_returnType() {
3858 Source source = addSource(EngineTestCase.createSource(["typedef A A();"])); 4422 Source source = addSource("typedef A A();");
3859 resolve(source); 4423 resolve(source);
3860 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]); 4424 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]);
3861 verify([source]); 4425 verify([source]);
3862 } 4426 }
3863 4427
3864 void test_typeAliasCannotReferenceItself_returnType_indirect() { 4428 void test_typeAliasCannotReferenceItself_returnType_indirect() {
3865 Source source = addSource(EngineTestCase.createSource(["typedef B A();", "ty pedef A B();"])); 4429 Source source = addSource(r'''
4430 typedef B A();
4431 typedef A B();''');
3866 resolve(source); 4432 resolve(source);
3867 assertErrors(source, [ 4433 assertErrors(source, [
3868 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 4434 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF,
3869 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); 4435 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]);
3870 verify([source]); 4436 verify([source]);
3871 } 4437 }
3872 4438
3873 void test_typeAliasCannotReferenceItself_typeVariableBounds() { 4439 void test_typeAliasCannotReferenceItself_typeVariableBounds() {
3874 Source source = addSource(EngineTestCase.createSource(["typedef A<T extends A>();"])); 4440 Source source = addSource("typedef A<T extends A>();");
3875 resolve(source); 4441 resolve(source);
3876 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]); 4442 assertErrors(source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSEL F]);
3877 verify([source]); 4443 verify([source]);
3878 } 4444 }
3879 4445
3880 void test_typeArgumentNotMatchingBounds_const() { 4446 void test_typeArgumentNotMatchingBounds_const() {
3881 Source source = addSource(EngineTestCase.createSource([ 4447 Source source = addSource(r'''
3882 "class A {}", 4448 class A {}
3883 "class B {}", 4449 class B {}
3884 "class G<E extends A> {", 4450 class G<E extends A> {
3885 " const G();", 4451 const G();
3886 "}", 4452 }
3887 "f() { return const G<B>(); }"])); 4453 f() { return const G<B>(); }''');
3888 resolve(source); 4454 resolve(source);
3889 assertErrors(source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS ]); 4455 assertErrors(source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS ]);
3890 verify([source]); 4456 verify([source]);
3891 } 4457 }
3892 4458
3893 void test_undefinedClass_const() { 4459 void test_undefinedClass_const() {
3894 Source source = addSource(EngineTestCase.createSource(["f() {", " return co nst A();", "}"])); 4460 Source source = addSource(r'''
4461 f() {
4462 return const A();
4463 }''');
3895 resolve(source); 4464 resolve(source);
3896 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CLASS]); 4465 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CLASS]);
3897 verify([source]); 4466 verify([source]);
3898 } 4467 }
3899 4468
3900 void test_undefinedConstructorInInitializer_explicit_named() { 4469 void test_undefinedConstructorInInitializer_explicit_named() {
3901 Source source = addSource(EngineTestCase.createSource([ 4470 Source source = addSource(r'''
3902 "class A {}", 4471 class A {}
3903 "class B extends A {", 4472 class B extends A {
3904 " B() : super.named();", 4473 B() : super.named();
3905 "}"])); 4474 }''');
3906 resolve(source); 4475 resolve(source);
3907 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI ZER]); 4476 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI ZER]);
3908 // no verify(), "super.named()" is not resolved 4477 // no verify(), "super.named()" is not resolved
3909 } 4478 }
3910 4479
3911 void test_undefinedConstructorInInitializer_explicit_unnamed() { 4480 void test_undefinedConstructorInInitializer_explicit_unnamed() {
3912 Source source = addSource(EngineTestCase.createSource([ 4481 Source source = addSource(r'''
3913 "class A {", 4482 class A {
3914 " A.named() {}", 4483 A.named() {}
3915 "}", 4484 }
3916 "class B extends A {", 4485 class B extends A {
3917 " B() : super();", 4486 B() : super();
3918 "}"])); 4487 }''');
3919 resolve(source); 4488 resolve(source);
3920 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI ZER_DEFAULT]); 4489 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI ZER_DEFAULT]);
3921 verify([source]); 4490 verify([source]);
3922 } 4491 }
3923 4492
3924 void test_undefinedConstructorInInitializer_implicit() { 4493 void test_undefinedConstructorInInitializer_implicit() {
3925 Source source = addSource(EngineTestCase.createSource([ 4494 Source source = addSource(r'''
3926 "class A {", 4495 class A {
3927 " A.named() {}", 4496 A.named() {}
3928 "}", 4497 }
3929 "class B extends A {", 4498 class B extends A {
3930 " B();", 4499 B();
3931 "}"])); 4500 }''');
3932 resolve(source); 4501 resolve(source);
3933 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI ZER_DEFAULT]); 4502 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALI ZER_DEFAULT]);
3934 verify([source]); 4503 verify([source]);
3935 } 4504 }
3936 4505
3937 void test_undefinedNamedParameter() { 4506 void test_undefinedNamedParameter() {
3938 Source source = addSource(EngineTestCase.createSource([ 4507 Source source = addSource(r'''
3939 "class A {", 4508 class A {
3940 " const A();", 4509 const A();
3941 "}", 4510 }
3942 "main() {", 4511 main() {
3943 " const A(p: 0);", 4512 const A(p: 0);
3944 "}"])); 4513 }''');
3945 resolve(source); 4514 resolve(source);
3946 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]); 4515 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]);
3947 // no verify(), 'p' is not resolved 4516 // no verify(), 'p' is not resolved
3948 } 4517 }
3949 4518
3950 void test_uriDoesNotExist_export() { 4519 void test_uriDoesNotExist_export() {
3951 Source source = addSource(EngineTestCase.createSource(["export 'unknown.dart ';"])); 4520 Source source = addSource("export 'unknown.dart';");
3952 resolve(source); 4521 resolve(source);
3953 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 4522 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
3954 } 4523 }
3955 4524
3956 void test_uriDoesNotExist_import() { 4525 void test_uriDoesNotExist_import() {
3957 Source source = addSource(EngineTestCase.createSource(["import 'unknown.dart ';"])); 4526 Source source = addSource("import 'unknown.dart';");
3958 resolve(source); 4527 resolve(source);
3959 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 4528 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
3960 } 4529 }
3961 4530
3962 void test_uriDoesNotExist_part() { 4531 void test_uriDoesNotExist_part() {
3963 Source source = addSource(EngineTestCase.createSource(["part 'unknown.dart'; "])); 4532 Source source = addSource("part 'unknown.dart';");
3964 resolve(source); 4533 resolve(source);
3965 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 4534 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
3966 } 4535 }
3967 4536
3968 void test_uriWithInterpolation_constant() { 4537 void test_uriWithInterpolation_constant() {
3969 Source source = addSource(EngineTestCase.createSource(["import 'stuff_\$plat form.dart';"])); 4538 Source source = addSource("import 'stuff_\$platform.dart';");
3970 resolve(source); 4539 resolve(source);
3971 assertErrors(source, [ 4540 assertErrors(source, [
3972 CompileTimeErrorCode.URI_WITH_INTERPOLATION, 4541 CompileTimeErrorCode.URI_WITH_INTERPOLATION,
3973 StaticWarningCode.UNDEFINED_IDENTIFIER]); 4542 StaticWarningCode.UNDEFINED_IDENTIFIER]);
3974 // We cannot verify resolution with an unresolvable URI: 'stuff_$platform.da rt' 4543 // We cannot verify resolution with an unresolvable URI: 'stuff_$platform.da rt'
3975 } 4544 }
3976 4545
3977 void test_uriWithInterpolation_nonConstant() { 4546 void test_uriWithInterpolation_nonConstant() {
3978 Source source = addSource(EngineTestCase.createSource(["library lib;", "part '\${'a'}.dart';"])); 4547 Source source = addSource(r'''
4548 library lib;
4549 part '${'a'}.dart';''');
3979 resolve(source); 4550 resolve(source);
3980 assertErrors(source, [CompileTimeErrorCode.URI_WITH_INTERPOLATION]); 4551 assertErrors(source, [CompileTimeErrorCode.URI_WITH_INTERPOLATION]);
3981 // We cannot verify resolution with an unresolvable URI: '${'a'}.dart' 4552 // We cannot verify resolution with an unresolvable URI: '${'a'}.dart'
3982 } 4553 }
3983 4554
3984 void test_wrongNumberOfParametersForOperator_minus() { 4555 void test_wrongNumberOfParametersForOperator_minus() {
3985 Source source = addSource(EngineTestCase.createSource(["class A {", " opera tor -(a, b) {}", "}"])); 4556 Source source = addSource(r'''
4557 class A {
4558 operator -(a, b) {}
4559 }''');
3986 resolve(source); 4560 resolve(source);
3987 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OP ERATOR_MINUS]); 4561 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OP ERATOR_MINUS]);
3988 verify([source]); 4562 verify([source]);
3989 reset(); 4563 reset();
3990 } 4564 }
3991 4565
3992 void test_wrongNumberOfParametersForOperator_tilde() { 4566 void test_wrongNumberOfParametersForOperator_tilde() {
3993 _check_wrongNumberOfParametersForOperator("~", "a"); 4567 _check_wrongNumberOfParametersForOperator("~", "a");
3994 _check_wrongNumberOfParametersForOperator("~", "a, b"); 4568 _check_wrongNumberOfParametersForOperator("~", "a, b");
3995 } 4569 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4034 } 4608 }
4035 4609
4036 void test_wrongNumberOfParametersForSetter_function_tooMany() { 4610 void test_wrongNumberOfParametersForSetter_function_tooMany() {
4037 Source source = addSource("set x(a, b) {}"); 4611 Source source = addSource("set x(a, b) {}");
4038 resolve(source); 4612 resolve(source);
4039 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]); 4613 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]);
4040 verify([source]); 4614 verify([source]);
4041 } 4615 }
4042 4616
4043 void test_wrongNumberOfParametersForSetter_method_named() { 4617 void test_wrongNumberOfParametersForSetter_method_named() {
4044 Source source = addSource(EngineTestCase.createSource(["class A {", " set x ({p}) {}", "}"])); 4618 Source source = addSource(r'''
4619 class A {
4620 set x({p}) {}
4621 }''');
4045 resolve(source); 4622 resolve(source);
4046 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]); 4623 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]);
4047 verify([source]); 4624 verify([source]);
4048 } 4625 }
4049 4626
4050 void test_wrongNumberOfParametersForSetter_method_optional() { 4627 void test_wrongNumberOfParametersForSetter_method_optional() {
4051 Source source = addSource(EngineTestCase.createSource(["class A {", " set x ([p]) {}", "}"])); 4628 Source source = addSource(r'''
4629 class A {
4630 set x([p]) {}
4631 }''');
4052 resolve(source); 4632 resolve(source);
4053 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]); 4633 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]);
4054 verify([source]); 4634 verify([source]);
4055 } 4635 }
4056 4636
4057 void test_wrongNumberOfParametersForSetter_method_tooFew() { 4637 void test_wrongNumberOfParametersForSetter_method_tooFew() {
4058 Source source = addSource(EngineTestCase.createSource(["class A {", " set x () {}", "}"])); 4638 Source source = addSource(r'''
4639 class A {
4640 set x() {}
4641 }''');
4059 resolve(source); 4642 resolve(source);
4060 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]); 4643 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]);
4061 verify([source]); 4644 verify([source]);
4062 } 4645 }
4063 4646
4064 void test_wrongNumberOfParametersForSetter_method_tooMany() { 4647 void test_wrongNumberOfParametersForSetter_method_tooMany() {
4065 Source source = addSource(EngineTestCase.createSource(["class A {", " set x (a, b) {}", "}"])); 4648 Source source = addSource(r'''
4649 class A {
4650 set x(a, b) {}
4651 }''');
4066 resolve(source); 4652 resolve(source);
4067 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]); 4653 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SE TTER]);
4068 verify([source]); 4654 verify([source]);
4069 } 4655 }
4070 4656
4071 void _check_constEvalThrowsException_binary_null(String expr, bool resolved) { 4657 void _check_constEvalThrowsException_binary_null(String expr, bool resolved) {
4072 Source source = addSource("const C = ${expr};"); 4658 Source source = addSource("const C = ${expr};");
4073 resolve(source); 4659 resolve(source);
4074 if (resolved) { 4660 if (resolved) {
4075 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); 4661 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
4076 verify([source]); 4662 verify([source]);
4077 } else { 4663 } else {
4078 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); 4664 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
4079 // no verify(), 'null x' is not resolved 4665 // no verify(), 'null x' is not resolved
4080 } 4666 }
4081 reset(); 4667 reset();
4082 } 4668 }
4083 4669
4084 void _check_constEvalTypeBool_withParameter_binary(String expr) { 4670 void _check_constEvalTypeBool_withParameter_binary(String expr) {
4085 Source source = addSource(EngineTestCase.createSource([ 4671 Source source = addSource('''
4086 "class A {", 4672 class A {
4087 " final a;", 4673 final a;
4088 " const A(bool p) : a = ${expr};", 4674 const A(bool p) : a = $expr;
4089 "}"])); 4675 }''');
4090 resolve(source); 4676 resolve(source);
4091 assertErrors(source, [ 4677 assertErrors(source, [
4092 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 4678 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
4093 StaticTypeWarningCode.NON_BOOL_OPERAND]); 4679 StaticTypeWarningCode.NON_BOOL_OPERAND]);
4094 verify([source]); 4680 verify([source]);
4095 reset(); 4681 reset();
4096 } 4682 }
4097 4683
4098 void _check_constEvalTypeInt_withParameter_binary(String expr) { 4684 void _check_constEvalTypeInt_withParameter_binary(String expr) {
4099 Source source = addSource(EngineTestCase.createSource([ 4685 Source source = addSource('''
4100 "class A {", 4686 class A {
4101 " final a;", 4687 final a;
4102 " const A(int p) : a = ${expr};", 4688 const A(int p) : a = $expr;
4103 "}"])); 4689 }''');
4104 resolve(source); 4690 resolve(source);
4105 assertErrors(source, [ 4691 assertErrors(source, [
4106 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, 4692 CompileTimeErrorCode.CONST_EVAL_TYPE_INT,
4107 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 4693 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
4108 verify([source]); 4694 verify([source]);
4109 reset(); 4695 reset();
4110 } 4696 }
4111 4697
4112 void _check_constEvalTypeNum_withParameter_binary(String expr) { 4698 void _check_constEvalTypeNum_withParameter_binary(String expr) {
4113 Source source = addSource(EngineTestCase.createSource([ 4699 Source source = addSource('''
4114 "class A {", 4700 class A {
4115 " final a;", 4701 final a;
4116 " const A(num p) : a = ${expr};", 4702 const A(num p) : a = $expr;
4117 "}"])); 4703 }''');
4118 resolve(source); 4704 resolve(source);
4119 assertErrors(source, [ 4705 assertErrors(source, [
4120 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, 4706 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM,
4121 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 4707 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
4122 verify([source]); 4708 verify([source]);
4123 reset(); 4709 reset();
4124 } 4710 }
4125 4711
4126 void _check_wrongNumberOfParametersForOperator(String name, String parameters) { 4712 void _check_wrongNumberOfParametersForOperator(String name, String parameters) {
4127 Source source = addSource(EngineTestCase.createSource(["class A {", " opera tor ${name}(${parameters}) {}", "}"])); 4713 Source source = addSource('''
4714 class A {
4715 operator $name($parameters) {}
4716 }''');
4128 resolve(source); 4717 resolve(source);
4129 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OP ERATOR]); 4718 assertErrors(source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OP ERATOR]);
4130 verify([source]); 4719 verify([source]);
4131 reset(); 4720 reset();
4132 } 4721 }
4133 4722
4134 void _check_wrongNumberOfParametersForOperator1(String name) { 4723 void _check_wrongNumberOfParametersForOperator1(String name) {
4135 _check_wrongNumberOfParametersForOperator(name, ""); 4724 _check_wrongNumberOfParametersForOperator(name, "");
4136 _check_wrongNumberOfParametersForOperator(name, "a, b"); 4725 _check_wrongNumberOfParametersForOperator(name, "a, b");
4137 } 4726 }
4138 } 4727 }
4139 4728
4140 main() { 4729 main() {
4141 _ut.groupSep = ' | '; 4730 _ut.groupSep = ' | ';
4142 runReflectiveTests(CompileTimeErrorCodeTest); 4731 runReflectiveTests(CompileTimeErrorCodeTest);
4143 } 4732 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/ast_test.dart ('k') | pkg/analyzer/test/generated/element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698