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

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

Issue 2626653002: Remove computeLibrarySourceErrors(). (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 analyzer.test.generated.compile_time_error_code_test; 5 library analyzer.test.generated.compile_time_error_code_test;
6 6
7 import 'package:analyzer/error/error.dart'; 7 import 'package:analyzer/error/error.dart';
8 import 'package:analyzer/src/error/codes.dart'; 8 import 'package:analyzer/src/error/codes.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; 10 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
(...skipping 12 matching lines...) Expand all
23 @reflectiveTest 23 @reflectiveTest
24 class CompileTimeErrorCodeTest extends ResolverTestCase { 24 class CompileTimeErrorCodeTest extends ResolverTestCase {
25 void fail_awaitInWrongContext_sync() { 25 void fail_awaitInWrongContext_sync() {
26 // This test requires better error recovery than we currently have. In 26 // This test requires better error recovery than we currently have. In
27 // particular, we need to be able to distinguish between an await expression 27 // particular, we need to be able to distinguish between an await expression
28 // in the wrong context, and the use of 'await' as an identifier. 28 // in the wrong context, and the use of 'await' as an identifier.
29 Source source = addSource(r''' 29 Source source = addSource(r'''
30 f(x) { 30 f(x) {
31 return await x; 31 return await x;
32 }'''); 32 }''');
33 computeLibrarySourceErrors(source);
34 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); 33 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]);
35 verify([source]); 34 verify([source]);
36 } 35 }
37 36
38 void fail_awaitInWrongContext_syncStar() { 37 void fail_awaitInWrongContext_syncStar() {
39 // This test requires better error recovery than we currently have. In 38 // This test requires better error recovery than we currently have. In
40 // particular, we need to be able to distinguish between an await expression 39 // particular, we need to be able to distinguish between an await expression
41 // in the wrong context, and the use of 'await' as an identifier. 40 // in the wrong context, and the use of 'await' as an identifier.
42 Source source = addSource(r''' 41 Source source = addSource(r'''
43 f(x) sync* { 42 f(x) sync* {
44 yield await x; 43 yield await x;
45 }'''); 44 }''');
46 computeLibrarySourceErrors(source);
47 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); 45 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]);
48 verify([source]); 46 verify([source]);
49 } 47 }
50 48
51 void fail_constEvalThrowsException() { 49 void fail_constEvalThrowsException() {
52 Source source = addSource(r''' 50 Source source = addSource(r'''
53 class C { 51 class C {
54 const C(); 52 const C();
55 } 53 }
56 f() { return const C(); }'''); 54 f() { return const C(); }''');
57 computeLibrarySourceErrors(source);
58 assertErrors( 55 assertErrors(
59 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION]); 56 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION]);
60 verify([source]); 57 verify([source]);
61 } 58 }
62 59
63 void fail_invalidIdentifierInAsync_async() { 60 void fail_invalidIdentifierInAsync_async() {
64 // TODO(brianwilkerson) Report this error. 61 // TODO(brianwilkerson) Report this error.
65 Source source = addSource(r''' 62 Source source = addSource(r'''
66 class A { 63 class A {
67 m() async { 64 m() async {
68 int async; 65 int async;
69 } 66 }
70 }'''); 67 }''');
71 computeLibrarySourceErrors(source);
72 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); 68 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]);
73 verify([source]); 69 verify([source]);
74 } 70 }
75 71
76 void fail_invalidIdentifierInAsync_await() { 72 void fail_invalidIdentifierInAsync_await() {
77 // TODO(brianwilkerson) Report this error. 73 // TODO(brianwilkerson) Report this error.
78 Source source = addSource(r''' 74 Source source = addSource(r'''
79 class A { 75 class A {
80 m() async { 76 m() async {
81 int await; 77 int await;
82 } 78 }
83 }'''); 79 }''');
84 computeLibrarySourceErrors(source);
85 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); 80 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]);
86 verify([source]); 81 verify([source]);
87 } 82 }
88 83
89 void fail_invalidIdentifierInAsync_yield() { 84 void fail_invalidIdentifierInAsync_yield() {
90 // TODO(brianwilkerson) Report this error. 85 // TODO(brianwilkerson) Report this error.
91 Source source = addSource(r''' 86 Source source = addSource(r'''
92 class A { 87 class A {
93 m() async { 88 m() async {
94 int yield; 89 int yield;
95 } 90 }
96 }'''); 91 }''');
97 computeLibrarySourceErrors(source);
98 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); 92 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]);
99 verify([source]); 93 verify([source]);
100 } 94 }
101 95
102 void fail_mixinDeclaresConstructor() { 96 void fail_mixinDeclaresConstructor() {
103 Source source = addSource(r''' 97 Source source = addSource(r'''
104 class A { 98 class A {
105 A() {} 99 A() {}
106 } 100 }
107 class B extends Object mixin A {}'''); 101 class B extends Object mixin A {}''');
108 computeLibrarySourceErrors(source);
109 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); 102 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
110 verify([source]); 103 verify([source]);
111 } 104 }
112 105
113 void fail_mixinOfNonClass() { 106 void fail_mixinOfNonClass() {
114 // TODO(brianwilkerson) Compare with MIXIN_WITH_NON_CLASS_SUPERCLASS. 107 // TODO(brianwilkerson) Compare with MIXIN_WITH_NON_CLASS_SUPERCLASS.
115 Source source = addSource(r''' 108 Source source = addSource(r'''
116 var A; 109 var A;
117 class B extends Object mixin A {}'''); 110 class B extends Object mixin A {}''');
118 computeLibrarySourceErrors(source);
119 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); 111 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]);
120 verify([source]); 112 verify([source]);
121 } 113 }
122 114
123 void fail_objectCannotExtendAnotherClass() { 115 void fail_objectCannotExtendAnotherClass() {
124 Source source = addSource(r''' 116 Source source = addSource(r'''
125 '''); 117 ''');
126 computeLibrarySourceErrors(source);
127 assertErrors( 118 assertErrors(
128 source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLASS]); 119 source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLASS]);
129 verify([source]); 120 verify([source]);
130 } 121 }
131 122
132 void fail_superInitializerInObject() { 123 void fail_superInitializerInObject() {
133 Source source = addSource(r''' 124 Source source = addSource(r'''
134 '''); 125 ''');
135 computeLibrarySourceErrors(source);
136 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]); 126 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]);
137 verify([source]); 127 verify([source]);
138 } 128 }
139 129
140 void fail_yieldEachInNonGenerator_async() { 130 void fail_yieldEachInNonGenerator_async() {
141 // TODO(brianwilkerson) We are currently parsing the yield statement as a 131 // TODO(brianwilkerson) We are currently parsing the yield statement as a
142 // binary expression. 132 // binary expression.
143 Source source = addSource(r''' 133 Source source = addSource(r'''
144 f() async { 134 f() async {
145 yield* 0; 135 yield* 0;
146 }'''); 136 }''');
147 computeLibrarySourceErrors(source);
148 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); 137 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]);
149 verify([source]); 138 verify([source]);
150 } 139 }
151 140
152 void fail_yieldEachInNonGenerator_sync() { 141 void fail_yieldEachInNonGenerator_sync() {
153 // TODO(brianwilkerson) We are currently parsing the yield statement as a 142 // TODO(brianwilkerson) We are currently parsing the yield statement as a
154 // binary expression. 143 // binary expression.
155 Source source = addSource(r''' 144 Source source = addSource(r'''
156 f() { 145 f() {
157 yield* 0; 146 yield* 0;
158 }'''); 147 }''');
159 computeLibrarySourceErrors(source);
160 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); 148 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]);
161 verify([source]); 149 verify([source]);
162 } 150 }
163 151
164 void fail_yieldInNonGenerator_async() { 152 void fail_yieldInNonGenerator_async() {
165 // TODO(brianwilkerson) We are currently trying to parse the yield statement 153 // TODO(brianwilkerson) We are currently trying to parse the yield statement
166 // as a binary expression. 154 // as a binary expression.
167 Source source = addSource(r''' 155 Source source = addSource(r'''
168 f() async { 156 f() async {
169 yield 0; 157 yield 0;
170 }'''); 158 }''');
171 computeLibrarySourceErrors(source);
172 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); 159 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]);
173 verify([source]); 160 verify([source]);
174 } 161 }
175 162
176 void fail_yieldInNonGenerator_sync() { 163 void fail_yieldInNonGenerator_sync() {
177 // TODO(brianwilkerson) We are currently trying to parse the yield statement 164 // TODO(brianwilkerson) We are currently trying to parse the yield statement
178 // as a binary expression. 165 // as a binary expression.
179 Source source = addSource(r''' 166 Source source = addSource(r'''
180 f() { 167 f() {
181 yield 0; 168 yield 0;
182 }'''); 169 }''');
183 computeLibrarySourceErrors(source);
184 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); 170 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]);
185 verify([source]); 171 verify([source]);
186 } 172 }
187 173
188 void test_accessPrivateEnumField() { 174 void test_accessPrivateEnumField() {
189 Source source = addSource(r''' 175 Source source = addSource(r'''
190 enum E { ONE } 176 enum E { ONE }
191 String name(E e) { 177 String name(E e) {
192 return e._name; 178 return e._name;
193 }'''); 179 }''');
194 computeLibrarySourceErrors(source);
195 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]); 180 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]);
196 // Cannot verify because "_name" cannot be resolved. 181 // Cannot verify because "_name" cannot be resolved.
197 } 182 }
198 183
199 void test_ambiguousExport() { 184 void test_ambiguousExport() {
200 Source source = addSource(r''' 185 Source source = addSource(r'''
201 library L; 186 library L;
202 export 'lib1.dart'; 187 export 'lib1.dart';
203 export 'lib2.dart';'''); 188 export 'lib2.dart';''');
204 addNamedSource( 189 addNamedSource(
205 "/lib1.dart", 190 "/lib1.dart",
206 r''' 191 r'''
207 library lib1; 192 library lib1;
208 class N {}'''); 193 class N {}''');
209 addNamedSource( 194 addNamedSource(
210 "/lib2.dart", 195 "/lib2.dart",
211 r''' 196 r'''
212 library lib2; 197 library lib2;
213 class N {}'''); 198 class N {}''');
214 computeLibrarySourceErrors(source);
215 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); 199 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]);
216 verify([source]); 200 verify([source]);
217 } 201 }
218 202
219 void test_annotationWithNotClass() { 203 void test_annotationWithNotClass() {
220 Source source = addSource(''' 204 Source source = addSource('''
221 class Property { 205 class Property {
222 final int value; 206 final int value;
223 const Property(this.value); 207 const Property(this.value);
224 } 208 }
225 209
226 const Property property = const Property(42); 210 const Property property = const Property(42);
227 211
228 @property(123) 212 @property(123)
229 main() { 213 main() {
230 } 214 }
231 '''); 215 ''');
232 computeLibrarySourceErrors(source);
233 assertErrors(source, [CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS]); 216 assertErrors(source, [CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS]);
234 verify([source]); 217 verify([source]);
235 } 218 }
236 219
237 void test_annotationWithNotClass_prefixed() { 220 void test_annotationWithNotClass_prefixed() {
238 addNamedSource( 221 addNamedSource(
239 "/annotations.dart", 222 "/annotations.dart",
240 r''' 223 r'''
241 class Property { 224 class Property {
242 final int value; 225 final int value;
243 const Property(this.value); 226 const Property(this.value);
244 } 227 }
245 228
246 const Property property = const Property(42); 229 const Property property = const Property(42);
247 '''); 230 ''');
248 Source source = addSource(''' 231 Source source = addSource('''
249 import 'annotations.dart' as pref; 232 import 'annotations.dart' as pref;
250 @pref.property(123) 233 @pref.property(123)
251 main() { 234 main() {
252 } 235 }
253 '''); 236 ''');
254 computeLibrarySourceErrors(source);
255 assertErrors(source, [CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS]); 237 assertErrors(source, [CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS]);
256 verify([source]); 238 verify([source]);
257 } 239 }
258 240
259 void test_async_used_as_identifier_in_annotation() { 241 void test_async_used_as_identifier_in_annotation() {
260 Source source = addSource(''' 242 Source source = addSource('''
261 const int async = 0; 243 const int async = 0;
262 f() async { 244 f() async {
263 g(@async x) {} 245 g(@async x) {}
264 g(0); 246 g(0);
265 } 247 }
266 '''); 248 ''');
267 computeLibrarySourceErrors(source);
268 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 249 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
269 verify([source]); 250 verify([source]);
270 } 251 }
271 252
272 void test_async_used_as_identifier_in_argument_label() { 253 void test_async_used_as_identifier_in_argument_label() {
273 Source source = addSource(''' 254 Source source = addSource('''
274 @proxy 255 @proxy
275 class C {} 256 class C {}
276 f() async { 257 f() async {
277 new C().g(async: 0); 258 new C().g(async: 0);
278 } 259 }
279 '''); 260 ''');
280 computeLibrarySourceErrors(source);
281 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 261 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
282 // Note: we don't call verify([source]) because verify() doesn't understand 262 // Note: we don't call verify([source]) because verify() doesn't understand
283 // about @proxy. 263 // about @proxy.
284 } 264 }
285 265
286 void test_async_used_as_identifier_in_async_method() { 266 void test_async_used_as_identifier_in_async_method() {
287 Source source = addSource(''' 267 Source source = addSource('''
288 f() async { 268 f() async {
289 var async = 1; 269 var async = 1;
290 } 270 }
291 '''); 271 ''');
292 computeLibrarySourceErrors(source);
293 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 272 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
294 verify([source]); 273 verify([source]);
295 } 274 }
296 275
297 void test_async_used_as_identifier_in_async_star_method() { 276 void test_async_used_as_identifier_in_async_star_method() {
298 Source source = addSource(''' 277 Source source = addSource('''
299 f() async* { 278 f() async* {
300 var async = 1; 279 var async = 1;
301 } 280 }
302 '''); 281 ''');
303 computeLibrarySourceErrors(source);
304 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 282 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
305 verify([source]); 283 verify([source]);
306 } 284 }
307 285
308 void test_async_used_as_identifier_in_break_statement() { 286 void test_async_used_as_identifier_in_break_statement() {
309 Source source = addSource(''' 287 Source source = addSource('''
310 f() async { 288 f() async {
311 while (true) { 289 while (true) {
312 break async; 290 break async;
313 } 291 }
314 } 292 }
315 '''); 293 ''');
316 computeLibrarySourceErrors(source);
317 assertErrors(source, [ 294 assertErrors(source, [
318 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, 295 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER,
319 CompileTimeErrorCode.LABEL_UNDEFINED 296 CompileTimeErrorCode.LABEL_UNDEFINED
320 ]); 297 ]);
321 // Note: we don't call verify([source]) because the reference to the 298 // Note: we don't call verify([source]) because the reference to the
322 // "async" label is unresolved. 299 // "async" label is unresolved.
323 } 300 }
324 301
325 void test_async_used_as_identifier_in_cascaded_invocation() { 302 void test_async_used_as_identifier_in_cascaded_invocation() {
326 Source source = addSource(''' 303 Source source = addSource('''
327 class C { 304 class C {
328 int async() => 1; 305 int async() => 1;
329 } 306 }
330 f() async { 307 f() async {
331 return new C()..async(); 308 return new C()..async();
332 } 309 }
333 '''); 310 ''');
334 computeLibrarySourceErrors(source);
335 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 311 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
336 verify([source]); 312 verify([source]);
337 } 313 }
338 314
339 void test_async_used_as_identifier_in_cascaded_setter_invocation() { 315 void test_async_used_as_identifier_in_cascaded_setter_invocation() {
340 Source source = addSource(''' 316 Source source = addSource('''
341 class C { 317 class C {
342 void set async(int i) {} 318 void set async(int i) {}
343 } 319 }
344 f() async { 320 f() async {
345 return new C()..async = 1; 321 return new C()..async = 1;
346 } 322 }
347 '''); 323 ''');
348 computeLibrarySourceErrors(source);
349 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 324 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
350 verify([source]); 325 verify([source]);
351 } 326 }
352 327
353 void test_async_used_as_identifier_in_catch_exception_argument() { 328 void test_async_used_as_identifier_in_catch_exception_argument() {
354 Source source = addSource(''' 329 Source source = addSource('''
355 g() {} 330 g() {}
356 f() async { 331 f() async {
357 try { 332 try {
358 g(); 333 g();
359 } catch (async) { } 334 } catch (async) { }
360 } 335 }
361 '''); 336 ''');
362 computeLibrarySourceErrors(source);
363 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 337 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
364 verify([source]); 338 verify([source]);
365 } 339 }
366 340
367 void test_async_used_as_identifier_in_catch_stacktrace_argument() { 341 void test_async_used_as_identifier_in_catch_stacktrace_argument() {
368 Source source = addSource(''' 342 Source source = addSource('''
369 g() {} 343 g() {}
370 f() async { 344 f() async {
371 try { 345 try {
372 g(); 346 g();
373 } catch (e, async) { } 347 } catch (e, async) { }
374 } 348 }
375 '''); 349 ''');
376 computeLibrarySourceErrors(source);
377 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 350 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
378 verify([source]); 351 verify([source]);
379 } 352 }
380 353
381 void test_async_used_as_identifier_in_continue_statement() { 354 void test_async_used_as_identifier_in_continue_statement() {
382 Source source = addSource(''' 355 Source source = addSource('''
383 f() async { 356 f() async {
384 while (true) { 357 while (true) {
385 continue async; 358 continue async;
386 } 359 }
387 } 360 }
388 '''); 361 ''');
389 computeLibrarySourceErrors(source);
390 assertErrors(source, [ 362 assertErrors(source, [
391 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, 363 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER,
392 CompileTimeErrorCode.LABEL_UNDEFINED 364 CompileTimeErrorCode.LABEL_UNDEFINED
393 ]); 365 ]);
394 // Note: we don't call verify([source]) because the reference to the 366 // Note: we don't call verify([source]) because the reference to the
395 // "async" label is unresolved. 367 // "async" label is unresolved.
396 } 368 }
397 369
398 void test_async_used_as_identifier_in_for_statement() { 370 void test_async_used_as_identifier_in_for_statement() {
399 Source source = addSource(''' 371 Source source = addSource('''
400 var async; 372 var async;
401 f() async { 373 f() async {
402 for (async in []) {} 374 for (async in []) {}
403 } 375 }
404 '''); 376 ''');
405 computeLibrarySourceErrors(source);
406 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 377 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
407 verify([source]); 378 verify([source]);
408 } 379 }
409 380
410 void test_async_used_as_identifier_in_formal_parameter_name() { 381 void test_async_used_as_identifier_in_formal_parameter_name() {
411 Source source = addSource(''' 382 Source source = addSource('''
412 f() async { 383 f() async {
413 g(int async) {} 384 g(int async) {}
414 g(0); 385 g(0);
415 } 386 }
416 '''); 387 ''');
417 computeLibrarySourceErrors(source);
418 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 388 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
419 verify([source]); 389 verify([source]);
420 } 390 }
421 391
422 void test_async_used_as_identifier_in_getter_name() { 392 void test_async_used_as_identifier_in_getter_name() {
423 Source source = addSource(''' 393 Source source = addSource('''
424 class C { 394 class C {
425 int get async => 1; 395 int get async => 1;
426 } 396 }
427 f() async { 397 f() async {
428 return new C().async; 398 return new C().async;
429 } 399 }
430 '''); 400 ''');
431 computeLibrarySourceErrors(source);
432 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 401 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
433 verify([source]); 402 verify([source]);
434 } 403 }
435 404
436 void test_async_used_as_identifier_in_invocation() { 405 void test_async_used_as_identifier_in_invocation() {
437 Source source = addSource(''' 406 Source source = addSource('''
438 class C { 407 class C {
439 int async() => 1; 408 int async() => 1;
440 } 409 }
441 f() async { 410 f() async {
442 return new C().async(); 411 return new C().async();
443 } 412 }
444 '''); 413 ''');
445 computeLibrarySourceErrors(source);
446 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 414 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
447 verify([source]); 415 verify([source]);
448 } 416 }
449 417
450 void test_async_used_as_identifier_in_local_function_name() { 418 void test_async_used_as_identifier_in_local_function_name() {
451 Source source = addSource(''' 419 Source source = addSource('''
452 f() async { 420 f() async {
453 int async() => null; 421 int async() => null;
454 } 422 }
455 '''); 423 ''');
456 computeLibrarySourceErrors(source);
457 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 424 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
458 verify([source]); 425 verify([source]);
459 } 426 }
460 427
461 void test_async_used_as_identifier_in_prefix() { 428 void test_async_used_as_identifier_in_prefix() {
462 Source source = addSource(''' 429 Source source = addSource('''
463 import 'dart:async' as async; 430 import 'dart:async' as async;
464 f() async { 431 f() async {
465 return new async.Future.value(0); 432 return new async.Future.value(0);
466 } 433 }
467 '''); 434 ''');
468 computeLibrarySourceErrors(source);
469 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 435 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
470 verify([source]); 436 verify([source]);
471 } 437 }
472 438
473 void test_async_used_as_identifier_in_setter_name() { 439 void test_async_used_as_identifier_in_setter_name() {
474 Source source = addSource(''' 440 Source source = addSource('''
475 class C { 441 class C {
476 void set async(int i) {} 442 void set async(int i) {}
477 } 443 }
478 f() async { 444 f() async {
479 new C().async = 1; 445 new C().async = 1;
480 } 446 }
481 '''); 447 ''');
482 computeLibrarySourceErrors(source);
483 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 448 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
484 verify([source]); 449 verify([source]);
485 } 450 }
486 451
487 void test_async_used_as_identifier_in_statement_label() { 452 void test_async_used_as_identifier_in_statement_label() {
488 Source source = addSource(''' 453 Source source = addSource('''
489 f() async { 454 f() async {
490 async: g(); 455 async: g();
491 } 456 }
492 g() {} 457 g() {}
493 '''); 458 ''');
494 computeLibrarySourceErrors(source);
495 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 459 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
496 verify([source]); 460 verify([source]);
497 } 461 }
498 462
499 void test_async_used_as_identifier_in_string_interpolation() { 463 void test_async_used_as_identifier_in_string_interpolation() {
500 Source source = addSource(r''' 464 Source source = addSource(r'''
501 int async = 1; 465 int async = 1;
502 f() async { 466 f() async {
503 return "$async"; 467 return "$async";
504 } 468 }
505 '''); 469 ''');
506 computeLibrarySourceErrors(source);
507 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 470 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
508 verify([source]); 471 verify([source]);
509 } 472 }
510 473
511 void test_async_used_as_identifier_in_suffix() { 474 void test_async_used_as_identifier_in_suffix() {
512 addNamedSource( 475 addNamedSource(
513 "/lib1.dart", 476 "/lib1.dart",
514 r''' 477 r'''
515 library lib1; 478 library lib1;
516 int async; 479 int async;
517 '''); 480 ''');
518 Source source = addSource(''' 481 Source source = addSource('''
519 import 'lib1.dart' as l; 482 import 'lib1.dart' as l;
520 f() async { 483 f() async {
521 return l.async; 484 return l.async;
522 } 485 }
523 '''); 486 ''');
524 computeLibrarySourceErrors(source);
525 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 487 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
526 verify([source]); 488 verify([source]);
527 } 489 }
528 490
529 void test_async_used_as_identifier_in_switch_label() { 491 void test_async_used_as_identifier_in_switch_label() {
530 Source source = addSource(''' 492 Source source = addSource('''
531 f() async { 493 f() async {
532 switch (0) { 494 switch (0) {
533 async: case 0: break; 495 async: case 0: break;
534 } 496 }
535 } 497 }
536 '''); 498 ''');
537 computeLibrarySourceErrors(source);
538 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 499 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
539 verify([source]); 500 verify([source]);
540 } 501 }
541 502
542 void test_async_used_as_identifier_in_sync_star_method() { 503 void test_async_used_as_identifier_in_sync_star_method() {
543 Source source = addSource(''' 504 Source source = addSource('''
544 f() sync* { 505 f() sync* {
545 var async = 1; 506 var async = 1;
546 } 507 }
547 '''); 508 ''');
548 computeLibrarySourceErrors(source);
549 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 509 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
550 verify([source]); 510 verify([source]);
551 } 511 }
552 512
553 void test_asyncForInWrongContext() { 513 void test_asyncForInWrongContext() {
554 Source source = addSource(r''' 514 Source source = addSource(r'''
555 f(list) { 515 f(list) {
556 await for (var e in list) { 516 await for (var e in list) {
557 } 517 }
558 }'''); 518 }''');
559 computeLibrarySourceErrors(source);
560 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]); 519 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]);
561 verify([source]); 520 verify([source]);
562 } 521 }
563 522
564 void test_await_used_as_identifier_in_async_method() { 523 void test_await_used_as_identifier_in_async_method() {
565 Source source = addSource(''' 524 Source source = addSource('''
566 f() async { 525 f() async {
567 var await = 1; 526 var await = 1;
568 } 527 }
569 '''); 528 ''');
570 computeLibrarySourceErrors(source);
571 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 529 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
572 verify([source]); 530 verify([source]);
573 } 531 }
574 532
575 void test_await_used_as_identifier_in_async_star_method() { 533 void test_await_used_as_identifier_in_async_star_method() {
576 Source source = addSource(''' 534 Source source = addSource('''
577 f() async* { 535 f() async* {
578 var await = 1; 536 var await = 1;
579 } 537 }
580 '''); 538 ''');
581 computeLibrarySourceErrors(source);
582 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 539 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
583 verify([source]); 540 verify([source]);
584 } 541 }
585 542
586 void test_await_used_as_identifier_in_sync_star_method() { 543 void test_await_used_as_identifier_in_sync_star_method() {
587 Source source = addSource(''' 544 Source source = addSource('''
588 f() sync* { 545 f() sync* {
589 var await = 1; 546 var await = 1;
590 } 547 }
591 '''); 548 ''');
592 computeLibrarySourceErrors(source);
593 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 549 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
594 verify([source]); 550 verify([source]);
595 } 551 }
596 552
597 void test_bug_23176() { 553 void test_bug_23176() {
598 Source source = addSource(''' 554 Source source = addSource('''
599 class A { 555 class A {
600 const A([x]); 556 const A([x]);
601 } 557 }
602 class B { 558 class B {
603 dynamic @A(const A()) x; 559 dynamic @A(const A()) x;
604 } 560 }
605 '''); 561 ''');
606 computeLibrarySourceErrors(source);
607 assertErrors(source, [ 562 assertErrors(source, [
608 ParserErrorCode.EXPECTED_CLASS_MEMBER, 563 ParserErrorCode.EXPECTED_CLASS_MEMBER,
609 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE 564 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE
610 ]); 565 ]);
611 verify([source]); 566 verify([source]);
612 } 567 }
613 568
614 void test_builtInIdentifierAsMixinName_classTypeAlias() { 569 void test_builtInIdentifierAsMixinName_classTypeAlias() {
615 Source source = addSource(r''' 570 Source source = addSource(r'''
616 class A {} 571 class A {}
617 class B {} 572 class B {}
618 class as = A with B;'''); 573 class as = A with B;''');
619 computeLibrarySourceErrors(source);
620 assertErrors( 574 assertErrors(
621 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]); 575 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]);
622 verify([source]); 576 verify([source]);
623 } 577 }
624 578
625 void test_builtInIdentifierAsType_formalParameter_field() { 579 void test_builtInIdentifierAsType_formalParameter_field() {
626 Source source = addSource(r''' 580 Source source = addSource(r'''
627 class A { 581 class A {
628 var x; 582 var x;
629 A(static this.x); 583 A(static this.x);
630 }'''); 584 }''');
631 computeLibrarySourceErrors(source);
632 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); 585 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]);
633 verify([source]); 586 verify([source]);
634 } 587 }
635 588
636 void test_builtInIdentifierAsType_formalParameter_simple() { 589 void test_builtInIdentifierAsType_formalParameter_simple() {
637 Source source = addSource(r''' 590 Source source = addSource(r'''
638 f(static x) { 591 f(static x) {
639 }'''); 592 }''');
640 computeLibrarySourceErrors(source);
641 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); 593 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]);
642 verify([source]); 594 verify([source]);
643 } 595 }
644 596
645 void test_builtInIdentifierAsType_variableDeclaration() { 597 void test_builtInIdentifierAsType_variableDeclaration() {
646 Source source = addSource(r''' 598 Source source = addSource(r'''
647 f() { 599 f() {
648 typedef x; 600 typedef x;
649 }'''); 601 }''');
650 computeLibrarySourceErrors(source);
651 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); 602 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]);
652 verify([source]); 603 verify([source]);
653 } 604 }
654 605
655 void test_builtInIdentifierAsTypedefName_functionTypeAlias() { 606 void test_builtInIdentifierAsTypedefName_functionTypeAlias() {
656 Source source = addSource("typedef bool as();"); 607 Source source = addSource("typedef bool as();");
657 computeLibrarySourceErrors(source);
658 assertErrors( 608 assertErrors(
659 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]); 609 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]);
660 verify([source]); 610 verify([source]);
661 } 611 }
662 612
663 void test_builtInIdentifierAsTypeName() { 613 void test_builtInIdentifierAsTypeName() {
664 Source source = addSource("class as {}"); 614 Source source = addSource("class as {}");
665 computeLibrarySourceErrors(source);
666 assertErrors( 615 assertErrors(
667 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME]); 616 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME]);
668 verify([source]); 617 verify([source]);
669 } 618 }
670 619
671 void test_builtInIdentifierAsTypeParameterName() { 620 void test_builtInIdentifierAsTypeParameterName() {
672 Source source = addSource("class A<as> {}"); 621 Source source = addSource("class A<as> {}");
673 computeLibrarySourceErrors(source);
674 assertErrors(source, 622 assertErrors(source,
675 [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME]); 623 [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME]);
676 verify([source]); 624 verify([source]);
677 } 625 }
678 626
679 void test_caseExpressionTypeImplementsEquals() { 627 void test_caseExpressionTypeImplementsEquals() {
680 Source source = addSource(r''' 628 Source source = addSource(r'''
681 class IntWrapper { 629 class IntWrapper {
682 final int value; 630 final int value;
683 const IntWrapper(this.value); 631 const IntWrapper(this.value);
684 bool operator ==(IntWrapper x) { 632 bool operator ==(IntWrapper x) {
685 return value == x.value; 633 return value == x.value;
686 } 634 }
687 get hashCode => value; 635 get hashCode => value;
688 } 636 }
689 637
690 f(var a) { 638 f(var a) {
691 switch(a) { 639 switch(a) {
692 case(const IntWrapper(1)) : return 1; 640 case(const IntWrapper(1)) : return 1;
693 default: return 0; 641 default: return 0;
694 } 642 }
695 }'''); 643 }''');
696 computeLibrarySourceErrors(source);
697 assertErrors( 644 assertErrors(
698 source, [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); 645 source, [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]);
699 verify([source]); 646 verify([source]);
700 } 647 }
701 648
702 void test_conflictingConstructorNameAndMember_field() { 649 void test_conflictingConstructorNameAndMember_field() {
703 Source source = addSource(r''' 650 Source source = addSource(r'''
704 class A { 651 class A {
705 int x; 652 int x;
706 A.x() {} 653 A.x() {}
707 }'''); 654 }''');
708 computeLibrarySourceErrors(source);
709 assertErrors( 655 assertErrors(
710 source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD]); 656 source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD]);
711 verify([source]); 657 verify([source]);
712 } 658 }
713 659
714 void test_conflictingConstructorNameAndMember_method() { 660 void test_conflictingConstructorNameAndMember_method() {
715 Source source = addSource(r''' 661 Source source = addSource(r'''
716 class A { 662 class A {
717 const A.x(); 663 const A.x();
718 void x() {} 664 void x() {}
719 }'''); 665 }''');
720 computeLibrarySourceErrors(source);
721 assertErrors( 666 assertErrors(
722 source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD]); 667 source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD]);
723 verify([source]); 668 verify([source]);
724 } 669 }
725 670
726 void test_conflictingGetterAndMethod_field_method() { 671 void test_conflictingGetterAndMethod_field_method() {
727 Source source = addSource(r''' 672 Source source = addSource(r'''
728 class A { 673 class A {
729 final int m = 0; 674 final int m = 0;
730 } 675 }
731 class B extends A { 676 class B extends A {
732 m() {} 677 m() {}
733 }'''); 678 }''');
734 computeLibrarySourceErrors(source);
735 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); 679 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]);
736 verify([source]); 680 verify([source]);
737 } 681 }
738 682
739 void test_conflictingGetterAndMethod_getter_method() { 683 void test_conflictingGetterAndMethod_getter_method() {
740 Source source = addSource(r''' 684 Source source = addSource(r'''
741 class A { 685 class A {
742 get m => 0; 686 get m => 0;
743 } 687 }
744 class B extends A { 688 class B extends A {
745 m() {} 689 m() {}
746 }'''); 690 }''');
747 computeLibrarySourceErrors(source);
748 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); 691 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]);
749 verify([source]); 692 verify([source]);
750 } 693 }
751 694
752 void test_conflictingGetterAndMethod_method_field() { 695 void test_conflictingGetterAndMethod_method_field() {
753 Source source = addSource(r''' 696 Source source = addSource(r'''
754 class A { 697 class A {
755 m() {} 698 m() {}
756 } 699 }
757 class B extends A { 700 class B extends A {
758 int m; 701 int m;
759 }'''); 702 }''');
760 computeLibrarySourceErrors(source);
761 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); 703 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]);
762 verify([source]); 704 verify([source]);
763 } 705 }
764 706
765 void test_conflictingGetterAndMethod_method_getter() { 707 void test_conflictingGetterAndMethod_method_getter() {
766 Source source = addSource(r''' 708 Source source = addSource(r'''
767 class A { 709 class A {
768 m() {} 710 m() {}
769 } 711 }
770 class B extends A { 712 class B extends A {
771 get m => 0; 713 get m => 0;
772 }'''); 714 }''');
773 computeLibrarySourceErrors(source);
774 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); 715 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]);
775 verify([source]); 716 verify([source]);
776 } 717 }
777 718
778 void test_conflictingTypeVariableAndClass() { 719 void test_conflictingTypeVariableAndClass() {
779 Source source = addSource(r''' 720 Source source = addSource(r'''
780 class T<T> { 721 class T<T> {
781 }'''); 722 }''');
782 computeLibrarySourceErrors(source);
783 assertErrors( 723 assertErrors(
784 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS]); 724 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS]);
785 verify([source]); 725 verify([source]);
786 } 726 }
787 727
788 void test_conflictingTypeVariableAndMember_field() { 728 void test_conflictingTypeVariableAndMember_field() {
789 Source source = addSource(r''' 729 Source source = addSource(r'''
790 class A<T> { 730 class A<T> {
791 var T; 731 var T;
792 }'''); 732 }''');
793 computeLibrarySourceErrors(source);
794 assertErrors( 733 assertErrors(
795 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); 734 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]);
796 verify([source]); 735 verify([source]);
797 } 736 }
798 737
799 void test_conflictingTypeVariableAndMember_getter() { 738 void test_conflictingTypeVariableAndMember_getter() {
800 Source source = addSource(r''' 739 Source source = addSource(r'''
801 class A<T> { 740 class A<T> {
802 get T => null; 741 get T => null;
803 }'''); 742 }''');
804 computeLibrarySourceErrors(source);
805 assertErrors( 743 assertErrors(
806 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); 744 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]);
807 verify([source]); 745 verify([source]);
808 } 746 }
809 747
810 void test_conflictingTypeVariableAndMember_method() { 748 void test_conflictingTypeVariableAndMember_method() {
811 Source source = addSource(r''' 749 Source source = addSource(r'''
812 class A<T> { 750 class A<T> {
813 T() {} 751 T() {}
814 }'''); 752 }''');
815 computeLibrarySourceErrors(source);
816 assertErrors( 753 assertErrors(
817 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); 754 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]);
818 verify([source]); 755 verify([source]);
819 } 756 }
820 757
821 void test_conflictingTypeVariableAndMember_method_static() { 758 void test_conflictingTypeVariableAndMember_method_static() {
822 Source source = addSource(r''' 759 Source source = addSource(r'''
823 class A<T> { 760 class A<T> {
824 static T() {} 761 static T() {}
825 }'''); 762 }''');
826 computeLibrarySourceErrors(source);
827 assertErrors( 763 assertErrors(
828 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); 764 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]);
829 verify([source]); 765 verify([source]);
830 } 766 }
831 767
832 void test_conflictingTypeVariableAndMember_setter() { 768 void test_conflictingTypeVariableAndMember_setter() {
833 Source source = addSource(r''' 769 Source source = addSource(r'''
834 class A<T> { 770 class A<T> {
835 set T(x) {} 771 set T(x) {}
836 }'''); 772 }''');
837 computeLibrarySourceErrors(source);
838 assertErrors( 773 assertErrors(
839 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); 774 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]);
840 verify([source]); 775 verify([source]);
841 } 776 }
842 777
843 void test_consistentCaseExpressionTypes_dynamic() { 778 void test_consistentCaseExpressionTypes_dynamic() {
844 // Even though A.S and S have a static type of "dynamic", we should see 779 // Even though A.S and S have a static type of "dynamic", we should see
845 // that they match 'abc', because they are constant strings. 780 // that they match 'abc', because they are constant strings.
846 Source source = addSource(r''' 781 Source source = addSource(r'''
847 class A { 782 class A {
848 static const S = 'A.S'; 783 static const S = 'A.S';
849 } 784 }
850 785
851 const S = 'S'; 786 const S = 'S';
852 787
853 foo(var p) { 788 foo(var p) {
854 switch (p) { 789 switch (p) {
855 case S: 790 case S:
856 break; 791 break;
857 case A.S: 792 case A.S:
858 break; 793 break;
859 case 'abc': 794 case 'abc':
860 break; 795 break;
861 } 796 }
862 }'''); 797 }''');
863 computeLibrarySourceErrors(source);
864 assertNoErrors(source); 798 assertNoErrors(source);
865 verify([source]); 799 verify([source]);
866 } 800 }
867 801
868 void test_constConstructorWithFieldInitializedByNonConst() { 802 void test_constConstructorWithFieldInitializedByNonConst() {
869 Source source = addSource(r''' 803 Source source = addSource(r'''
870 class A { 804 class A {
871 final int i = f(); 805 final int i = f();
872 const A(); 806 const A();
873 } 807 }
874 int f() { 808 int f() {
875 return 3; 809 return 3;
876 }'''); 810 }''');
877 computeLibrarySourceErrors(source);
878 // TODO(paulberry): the error CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE is 811 // TODO(paulberry): the error CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE is
879 // redundant and ought to be suppressed. 812 // redundant and ought to be suppressed.
880 assertErrors(source, [ 813 assertErrors(source, [
881 CompileTimeErrorCode 814 CompileTimeErrorCode
882 .CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST, 815 .CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST,
883 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE 816 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
884 ]); 817 ]);
885 verify([source]); 818 verify([source]);
886 } 819 }
887 820
888 void test_constConstructorWithFieldInitializedByNonConst_static() { 821 void test_constConstructorWithFieldInitializedByNonConst_static() {
889 Source source = addSource(r''' 822 Source source = addSource(r'''
890 class A { 823 class A {
891 static final int i = f(); 824 static final int i = f();
892 const A(); 825 const A();
893 } 826 }
894 int f() { 827 int f() {
895 return 3; 828 return 3;
896 }'''); 829 }''');
897 computeLibrarySourceErrors(source);
898 assertNoErrors(source); 830 assertNoErrors(source);
899 verify([source]); 831 verify([source]);
900 } 832 }
901 833
902 void test_constConstructorWithMixin() { 834 void test_constConstructorWithMixin() {
903 Source source = addSource(r''' 835 Source source = addSource(r'''
904 class M { 836 class M {
905 } 837 }
906 class A extends Object with M { 838 class A extends Object with M {
907 const A(); 839 const A();
908 }'''); 840 }''');
909 computeLibrarySourceErrors(source);
910 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]); 841 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]);
911 verify([source]); 842 verify([source]);
912 } 843 }
913 844
914 void test_constConstructorWithNonConstSuper_explicit() { 845 void test_constConstructorWithNonConstSuper_explicit() {
915 Source source = addSource(r''' 846 Source source = addSource(r'''
916 class A { 847 class A {
917 A(); 848 A();
918 } 849 }
919 class B extends A { 850 class B extends A {
920 const B(): super(); 851 const B(): super();
921 }'''); 852 }''');
922 computeLibrarySourceErrors(source);
923 assertErrors( 853 assertErrors(
924 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]); 854 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]);
925 verify([source]); 855 verify([source]);
926 } 856 }
927 857
928 void test_constConstructorWithNonConstSuper_implicit() { 858 void test_constConstructorWithNonConstSuper_implicit() {
929 Source source = addSource(r''' 859 Source source = addSource(r'''
930 class A { 860 class A {
931 A(); 861 A();
932 } 862 }
933 class B extends A { 863 class B extends A {
934 const B(); 864 const B();
935 }'''); 865 }''');
936 computeLibrarySourceErrors(source);
937 assertErrors( 866 assertErrors(
938 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]); 867 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]);
939 verify([source]); 868 verify([source]);
940 } 869 }
941 870
942 void test_constConstructorWithNonFinalField_mixin() { 871 void test_constConstructorWithNonFinalField_mixin() {
943 Source source = addSource(r''' 872 Source source = addSource(r'''
944 class A { 873 class A {
945 var a; 874 var a;
946 } 875 }
947 class B extends Object with A { 876 class B extends Object with A {
948 const B(); 877 const B();
949 }'''); 878 }''');
950 computeLibrarySourceErrors(source);
951 assertErrors(source, [ 879 assertErrors(source, [
952 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN, 880 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN,
953 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD 881 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD
954 ]); 882 ]);
955 verify([source]); 883 verify([source]);
956 } 884 }
957 885
958 void test_constConstructorWithNonFinalField_super() { 886 void test_constConstructorWithNonFinalField_super() {
959 Source source = addSource(r''' 887 Source source = addSource(r'''
960 class A { 888 class A {
961 var a; 889 var a;
962 } 890 }
963 class B extends A { 891 class B extends A {
964 const B(); 892 const B();
965 }'''); 893 }''');
966 computeLibrarySourceErrors(source);
967 assertErrors(source, [ 894 assertErrors(source, [
968 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD, 895 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD,
969 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER 896 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER
970 ]); 897 ]);
971 verify([source]); 898 verify([source]);
972 } 899 }
973 900
974 void test_constConstructorWithNonFinalField_this() { 901 void test_constConstructorWithNonFinalField_this() {
975 Source source = addSource(r''' 902 Source source = addSource(r'''
976 class A { 903 class A {
977 int x; 904 int x;
978 const A(); 905 const A();
979 }'''); 906 }''');
980 computeLibrarySourceErrors(source);
981 assertErrors( 907 assertErrors(
982 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]); 908 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]);
983 verify([source]); 909 verify([source]);
984 } 910 }
985 911
986 void test_constDeferredClass() { 912 void test_constDeferredClass() {
987 resolveWithErrors(<String>[ 913 resolveWithErrors(<String>[
988 r''' 914 r'''
989 library lib1; 915 library lib1;
990 class A { 916 class A {
(...skipping 27 matching lines...) Expand all
1018 CompileTimeErrorCode.CONST_DEFERRED_CLASS 944 CompileTimeErrorCode.CONST_DEFERRED_CLASS
1019 ]); 945 ]);
1020 } 946 }
1021 947
1022 void test_constEval_newInstance_constConstructor() { 948 void test_constEval_newInstance_constConstructor() {
1023 Source source = addSource(r''' 949 Source source = addSource(r'''
1024 class A { 950 class A {
1025 const A(); 951 const A();
1026 } 952 }
1027 const a = new A();'''); 953 const a = new A();''');
1028 computeLibrarySourceErrors(source);
1029 assertErrors(source, 954 assertErrors(source,
1030 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); 955 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1031 verify([source]); 956 verify([source]);
1032 } 957 }
1033 958
1034 void test_constEval_newInstance_externalFactoryConstConstructor() { 959 void test_constEval_newInstance_externalFactoryConstConstructor() {
1035 // We can't evaluate "const A()" because its constructor is external. But 960 // We can't evaluate "const A()" because its constructor is external. But
1036 // the code is correct--we shouldn't report an error. 961 // the code is correct--we shouldn't report an error.
1037 Source source = addSource(r''' 962 Source source = addSource(r'''
1038 class A { 963 class A {
1039 external factory const A(); 964 external factory const A();
1040 } 965 }
1041 const x = const A();'''); 966 const x = const A();''');
1042 computeLibrarySourceErrors(source);
1043 assertNoErrors(source); 967 assertNoErrors(source);
1044 verify([source]); 968 verify([source]);
1045 } 969 }
1046 970
1047 void test_constEval_nonStaticField_inGenericClass() { 971 void test_constEval_nonStaticField_inGenericClass() {
1048 Source source = addSource(''' 972 Source source = addSource('''
1049 class C<T> { 973 class C<T> {
1050 const C(); 974 const C();
1051 T get t => null; 975 T get t => null;
1052 } 976 }
1053 977
1054 const x = const C().t;'''); 978 const x = const C().t;''');
1055 computeLibrarySourceErrors(source);
1056 assertErrors(source, 979 assertErrors(source,
1057 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); 980 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1058 verify([source]); 981 verify([source]);
1059 } 982 }
1060 983
1061 void test_constEval_propertyExtraction_targetNotConst() { 984 void test_constEval_propertyExtraction_targetNotConst() {
1062 Source source = addSource(r''' 985 Source source = addSource(r'''
1063 class A { 986 class A {
1064 const A(); 987 const A();
1065 m() {} 988 m() {}
1066 } 989 }
1067 final a = const A(); 990 final a = const A();
1068 const C = a.m;'''); 991 const C = a.m;''');
1069 computeLibrarySourceErrors(source);
1070 assertErrors(source, 992 assertErrors(source,
1071 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); 993 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1072 verify([source]); 994 verify([source]);
1073 } 995 }
1074 996
1075 void test_constEvalThrowsException_binaryMinus_null() { 997 void test_constEvalThrowsException_binaryMinus_null() {
1076 _check_constEvalThrowsException_binary_null("null - 5", false); 998 _check_constEvalThrowsException_binary_null("null - 5", false);
1077 _check_constEvalThrowsException_binary_null("5 - null", true); 999 _check_constEvalThrowsException_binary_null("5 - null", true);
1078 } 1000 }
1079 1001
1080 void test_constEvalThrowsException_binaryPlus_null() { 1002 void test_constEvalThrowsException_binaryPlus_null() {
1081 _check_constEvalThrowsException_binary_null("null + 5", false); 1003 _check_constEvalThrowsException_binary_null("null + 5", false);
1082 _check_constEvalThrowsException_binary_null("5 + null", true); 1004 _check_constEvalThrowsException_binary_null("5 + null", true);
1083 } 1005 }
1084 1006
1085 void test_constEvalThrowsException_divisionByZero() { 1007 void test_constEvalThrowsException_divisionByZero() {
1086 Source source = addSource("const C = 1 ~/ 0;"); 1008 Source source = addSource("const C = 1 ~/ 0;");
1087 computeLibrarySourceErrors(source);
1088 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE]); 1009 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE]);
1089 verify([source]); 1010 verify([source]);
1090 } 1011 }
1091 1012
1092 void test_constEvalThrowsException_finalAlreadySet_initializer() { 1013 void test_constEvalThrowsException_finalAlreadySet_initializer() {
1093 // If a final variable has an initializer at the site of its declaration, 1014 // If a final variable has an initializer at the site of its declaration,
1094 // and at the site of the constructor, then invoking that constructor would 1015 // and at the site of the constructor, then invoking that constructor would
1095 // produce a runtime error; hence invoking that constructor via the "const" 1016 // produce a runtime error; hence invoking that constructor via the "const"
1096 // keyword results in a compile-time error. 1017 // keyword results in a compile-time error.
1097 Source source = addSource(''' 1018 Source source = addSource('''
1098 class C { 1019 class C {
1099 final x = 1; 1020 final x = 1;
1100 const C() : x = 2; 1021 const C() : x = 2;
1101 } 1022 }
1102 var x = const C(); 1023 var x = const C();
1103 '''); 1024 ''');
1104 computeLibrarySourceErrors(source);
1105 assertErrors(source, [ 1025 assertErrors(source, [
1106 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 1026 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
1107 StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION 1027 StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION
1108 ]); 1028 ]);
1109 verify([source]); 1029 verify([source]);
1110 } 1030 }
1111 1031
1112 void test_constEvalThrowsException_finalAlreadySet_initializing_formal() { 1032 void test_constEvalThrowsException_finalAlreadySet_initializing_formal() {
1113 // If a final variable has an initializer at the site of its declaration, 1033 // If a final variable has an initializer at the site of its declaration,
1114 // and it is initialized using an initializing formal at the site of the 1034 // and it is initialized using an initializing formal at the site of the
1115 // constructor, then invoking that constructor would produce a runtime 1035 // constructor, then invoking that constructor would produce a runtime
1116 // error; hence invoking that constructor via the "const" keyword results 1036 // error; hence invoking that constructor via the "const" keyword results
1117 // in a compile-time error. 1037 // in a compile-time error.
1118 Source source = addSource(''' 1038 Source source = addSource('''
1119 class C { 1039 class C {
1120 final x = 1; 1040 final x = 1;
1121 const C(this.x); 1041 const C(this.x);
1122 } 1042 }
1123 var x = const C(2); 1043 var x = const C(2);
1124 '''); 1044 ''');
1125 computeLibrarySourceErrors(source);
1126 assertErrors(source, [ 1045 assertErrors(source, [
1127 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 1046 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
1128 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR 1047 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR
1129 ]); 1048 ]);
1130 verify([source]); 1049 verify([source]);
1131 } 1050 }
1132 1051
1133 void test_constEvalThrowsException_unaryBitNot_null() { 1052 void test_constEvalThrowsException_unaryBitNot_null() {
1134 Source source = addSource("const C = ~null;"); 1053 Source source = addSource("const C = ~null;");
1135 computeLibrarySourceErrors(source);
1136 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); 1054 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
1137 // no verify(), '~null' is not resolved 1055 // no verify(), '~null' is not resolved
1138 } 1056 }
1139 1057
1140 void test_constEvalThrowsException_unaryNegated_null() { 1058 void test_constEvalThrowsException_unaryNegated_null() {
1141 Source source = addSource("const C = -null;"); 1059 Source source = addSource("const C = -null;");
1142 computeLibrarySourceErrors(source);
1143 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); 1060 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
1144 // no verify(), '-null' is not resolved 1061 // no verify(), '-null' is not resolved
1145 } 1062 }
1146 1063
1147 void test_constEvalThrowsException_unaryNot_null() { 1064 void test_constEvalThrowsException_unaryNot_null() {
1148 Source source = addSource("const C = !null;"); 1065 Source source = addSource("const C = !null;");
1149 computeLibrarySourceErrors(source);
1150 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); 1066 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
1151 verify([source]); 1067 verify([source]);
1152 } 1068 }
1153 1069
1154 void test_constEvalTypeBool_binary() { 1070 void test_constEvalTypeBool_binary() {
1155 _check_constEvalTypeBool_withParameter_binary("p && ''"); 1071 _check_constEvalTypeBool_withParameter_binary("p && ''");
1156 _check_constEvalTypeBool_withParameter_binary("p || ''"); 1072 _check_constEvalTypeBool_withParameter_binary("p || ''");
1157 } 1073 }
1158 1074
1159 void test_constEvalTypeBool_binary_leftTrue() { 1075 void test_constEvalTypeBool_binary_leftTrue() {
1160 Source source = addSource("const C = (true || 0);"); 1076 Source source = addSource("const C = (true || 0);");
1161 computeLibrarySourceErrors(source);
1162 assertErrors(source, [ 1077 assertErrors(source, [
1163 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 1078 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
1164 StaticTypeWarningCode.NON_BOOL_OPERAND, 1079 StaticTypeWarningCode.NON_BOOL_OPERAND,
1165 HintCode.DEAD_CODE 1080 HintCode.DEAD_CODE
1166 ]); 1081 ]);
1167 verify([source]); 1082 verify([source]);
1168 } 1083 }
1169 1084
1170 void test_constEvalTypeBoolNumString_equal() { 1085 void test_constEvalTypeBoolNumString_equal() {
1171 Source source = addSource(r''' 1086 Source source = addSource(r'''
1172 class A { 1087 class A {
1173 const A(); 1088 const A();
1174 } 1089 }
1175 class B { 1090 class B {
1176 final a; 1091 final a;
1177 const B(num p) : a = p == const A(); 1092 const B(num p) : a = p == const A();
1178 }'''); 1093 }''');
1179 computeLibrarySourceErrors(source);
1180 assertErrors( 1094 assertErrors(
1181 source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]); 1095 source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]);
1182 verify([source]); 1096 verify([source]);
1183 } 1097 }
1184 1098
1185 void test_constEvalTypeBoolNumString_notEqual() { 1099 void test_constEvalTypeBoolNumString_notEqual() {
1186 Source source = addSource(r''' 1100 Source source = addSource(r'''
1187 class A { 1101 class A {
1188 const A(); 1102 const A();
1189 } 1103 }
1190 class B { 1104 class B {
1191 final a; 1105 final a;
1192 const B(String p) : a = p != const A(); 1106 const B(String p) : a = p != const A();
1193 }'''); 1107 }''');
1194 computeLibrarySourceErrors(source);
1195 assertErrors( 1108 assertErrors(
1196 source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]); 1109 source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]);
1197 verify([source]); 1110 verify([source]);
1198 } 1111 }
1199 1112
1200 void test_constEvalTypeInt_binary() { 1113 void test_constEvalTypeInt_binary() {
1201 _check_constEvalTypeInt_withParameter_binary("p ^ ''"); 1114 _check_constEvalTypeInt_withParameter_binary("p ^ ''");
1202 _check_constEvalTypeInt_withParameter_binary("p & ''"); 1115 _check_constEvalTypeInt_withParameter_binary("p & ''");
1203 _check_constEvalTypeInt_withParameter_binary("p | ''"); 1116 _check_constEvalTypeInt_withParameter_binary("p | ''");
1204 _check_constEvalTypeInt_withParameter_binary("p >> ''"); 1117 _check_constEvalTypeInt_withParameter_binary("p >> ''");
(...skipping 12 matching lines...) Expand all
1217 _check_constEvalTypeNum_withParameter_binary("p <= ''"); 1130 _check_constEvalTypeNum_withParameter_binary("p <= ''");
1218 _check_constEvalTypeNum_withParameter_binary("p % ''"); 1131 _check_constEvalTypeNum_withParameter_binary("p % ''");
1219 } 1132 }
1220 1133
1221 void test_constFormalParameter_fieldFormalParameter() { 1134 void test_constFormalParameter_fieldFormalParameter() {
1222 Source source = addSource(r''' 1135 Source source = addSource(r'''
1223 class A { 1136 class A {
1224 var x; 1137 var x;
1225 A(const this.x) {} 1138 A(const this.x) {}
1226 }'''); 1139 }''');
1227 computeLibrarySourceErrors(source);
1228 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); 1140 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]);
1229 verify([source]); 1141 verify([source]);
1230 } 1142 }
1231 1143
1232 void test_constFormalParameter_simpleFormalParameter() { 1144 void test_constFormalParameter_simpleFormalParameter() {
1233 Source source = addSource("f(const x) {}"); 1145 Source source = addSource("f(const x) {}");
1234 computeLibrarySourceErrors(source);
1235 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); 1146 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]);
1236 verify([source]); 1147 verify([source]);
1237 } 1148 }
1238 1149
1239 void test_constInitializedWithNonConstValue() { 1150 void test_constInitializedWithNonConstValue() {
1240 Source source = addSource(r''' 1151 Source source = addSource(r'''
1241 f(p) { 1152 f(p) {
1242 const C = p; 1153 const C = p;
1243 }'''); 1154 }''');
1244 computeLibrarySourceErrors(source);
1245 assertErrors(source, 1155 assertErrors(source,
1246 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); 1156 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1247 verify([source]); 1157 verify([source]);
1248 } 1158 }
1249 1159
1250 void test_constInitializedWithNonConstValue_finalField() { 1160 void test_constInitializedWithNonConstValue_finalField() {
1251 // Regression test for bug #25526 which previously 1161 // Regression test for bug #25526 which previously
1252 // caused two errors to be reported. 1162 // caused two errors to be reported.
1253 Source source = addSource(r''' 1163 Source source = addSource(r'''
1254 class Foo { 1164 class Foo {
1255 final field = []; 1165 final field = [];
1256 foo([int x = field]) {} 1166 foo([int x = field]) {}
1257 } 1167 }
1258 '''); 1168 ''');
1259 computeLibrarySourceErrors(source);
1260 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 1169 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
1261 verify([source]); 1170 verify([source]);
1262 } 1171 }
1263 1172
1264 void test_constInitializedWithNonConstValue_missingConstInListLiteral() { 1173 void test_constInitializedWithNonConstValue_missingConstInListLiteral() {
1265 Source source = addSource("const List L = [0];"); 1174 Source source = addSource("const List L = [0];");
1266 computeLibrarySourceErrors(source);
1267 assertErrors(source, 1175 assertErrors(source,
1268 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); 1176 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1269 verify([source]); 1177 verify([source]);
1270 } 1178 }
1271 1179
1272 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() { 1180 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() {
1273 Source source = addSource("const Map M = {'a' : 0};"); 1181 Source source = addSource("const Map M = {'a' : 0};");
1274 computeLibrarySourceErrors(source);
1275 assertErrors(source, 1182 assertErrors(source,
1276 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); 1183 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1277 verify([source]); 1184 verify([source]);
1278 } 1185 }
1279 1186
1280 void test_constInitializedWithNonConstValueFromDeferredClass() { 1187 void test_constInitializedWithNonConstValueFromDeferredClass() {
1281 resolveWithErrors(<String>[ 1188 resolveWithErrors(<String>[
1282 r''' 1189 r'''
1283 library lib1; 1190 library lib1;
1284 const V = 1;''', 1191 const V = 1;''',
(...skipping 20 matching lines...) Expand all
1305 CompileTimeErrorCode 1212 CompileTimeErrorCode
1306 .CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY 1213 .CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY
1307 ]); 1214 ]);
1308 } 1215 }
1309 1216
1310 void test_constInstanceField() { 1217 void test_constInstanceField() {
1311 Source source = addSource(r''' 1218 Source source = addSource(r'''
1312 class C { 1219 class C {
1313 const int f = 0; 1220 const int f = 0;
1314 }'''); 1221 }''');
1315 computeLibrarySourceErrors(source);
1316 assertErrors(source, [CompileTimeErrorCode.CONST_INSTANCE_FIELD]); 1222 assertErrors(source, [CompileTimeErrorCode.CONST_INSTANCE_FIELD]);
1317 verify([source]); 1223 verify([source]);
1318 } 1224 }
1319 1225
1320 void test_constMapKeyTypeImplementsEquals_direct() { 1226 void test_constMapKeyTypeImplementsEquals_direct() {
1321 Source source = addSource(r''' 1227 Source source = addSource(r'''
1322 class A { 1228 class A {
1323 const A(); 1229 const A();
1324 operator ==(other) => false; 1230 operator ==(other) => false;
1325 } 1231 }
1326 main() { 1232 main() {
1327 const {const A() : 0}; 1233 const {const A() : 0};
1328 }'''); 1234 }''');
1329 computeLibrarySourceErrors(source);
1330 assertErrors(source, 1235 assertErrors(source,
1331 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); 1236 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]);
1332 verify([source]); 1237 verify([source]);
1333 } 1238 }
1334 1239
1335 void test_constMapKeyTypeImplementsEquals_dynamic() { 1240 void test_constMapKeyTypeImplementsEquals_dynamic() {
1336 // Note: static type of B.a is "dynamic", but actual type of the const 1241 // Note: static type of B.a is "dynamic", but actual type of the const
1337 // object is A. We need to make sure we examine the actual type when 1242 // object is A. We need to make sure we examine the actual type when
1338 // deciding whether there is a problem with operator==. 1243 // deciding whether there is a problem with operator==.
1339 Source source = addSource(r''' 1244 Source source = addSource(r'''
1340 class A { 1245 class A {
1341 const A(); 1246 const A();
1342 operator ==(other) => false; 1247 operator ==(other) => false;
1343 } 1248 }
1344 class B { 1249 class B {
1345 static const a = const A(); 1250 static const a = const A();
1346 } 1251 }
1347 main() { 1252 main() {
1348 const {B.a : 0}; 1253 const {B.a : 0};
1349 }'''); 1254 }''');
1350 computeLibrarySourceErrors(source);
1351 assertErrors(source, 1255 assertErrors(source,
1352 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); 1256 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]);
1353 verify([source]); 1257 verify([source]);
1354 } 1258 }
1355 1259
1356 void test_constMapKeyTypeImplementsEquals_factory() { 1260 void test_constMapKeyTypeImplementsEquals_factory() {
1357 Source source = addSource(r''' 1261 Source source = addSource(r'''
1358 class A { const factory A() = B; } 1262 class A { const factory A() = B; }
1359 1263
1360 class B implements A { 1264 class B implements A {
1361 const B(); 1265 const B();
1362 1266
1363 operator ==(o) => true; 1267 operator ==(o) => true;
1364 } 1268 }
1365 1269
1366 main() { 1270 main() {
1367 var m = const { const A(): 42 }; 1271 var m = const { const A(): 42 };
1368 }'''); 1272 }''');
1369 computeLibrarySourceErrors(source);
1370 assertErrors(source, 1273 assertErrors(source,
1371 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); 1274 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]);
1372 verify([source]); 1275 verify([source]);
1373 } 1276 }
1374 1277
1375 void test_constMapKeyTypeImplementsEquals_super() { 1278 void test_constMapKeyTypeImplementsEquals_super() {
1376 Source source = addSource(r''' 1279 Source source = addSource(r'''
1377 class A { 1280 class A {
1378 const A(); 1281 const A();
1379 operator ==(other) => false; 1282 operator ==(other) => false;
1380 } 1283 }
1381 class B extends A { 1284 class B extends A {
1382 const B(); 1285 const B();
1383 } 1286 }
1384 main() { 1287 main() {
1385 const {const B() : 0}; 1288 const {const B() : 0};
1386 }'''); 1289 }''');
1387 computeLibrarySourceErrors(source);
1388 assertErrors(source, 1290 assertErrors(source,
1389 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); 1291 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]);
1390 verify([source]); 1292 verify([source]);
1391 } 1293 }
1392 1294
1393 void test_constWithInvalidTypeParameters() { 1295 void test_constWithInvalidTypeParameters() {
1394 Source source = addSource(r''' 1296 Source source = addSource(r'''
1395 class A { 1297 class A {
1396 const A(); 1298 const A();
1397 } 1299 }
1398 f() { return const A<A>(); }'''); 1300 f() { return const A<A>(); }''');
1399 computeLibrarySourceErrors(source);
1400 assertErrors( 1301 assertErrors(
1401 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]); 1302 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]);
1402 verify([source]); 1303 verify([source]);
1403 } 1304 }
1404 1305
1405 void test_constWithInvalidTypeParameters_tooFew() { 1306 void test_constWithInvalidTypeParameters_tooFew() {
1406 Source source = addSource(r''' 1307 Source source = addSource(r'''
1407 class A {} 1308 class A {}
1408 class C<K, V> { 1309 class C<K, V> {
1409 const C(); 1310 const C();
1410 } 1311 }
1411 f(p) { 1312 f(p) {
1412 return const C<A>(); 1313 return const C<A>();
1413 }'''); 1314 }''');
1414 computeLibrarySourceErrors(source);
1415 assertErrors( 1315 assertErrors(
1416 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]); 1316 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]);
1417 verify([source]); 1317 verify([source]);
1418 } 1318 }
1419 1319
1420 void test_constWithInvalidTypeParameters_tooMany() { 1320 void test_constWithInvalidTypeParameters_tooMany() {
1421 Source source = addSource(r''' 1321 Source source = addSource(r'''
1422 class A {} 1322 class A {}
1423 class C<E> { 1323 class C<E> {
1424 const C(); 1324 const C();
1425 } 1325 }
1426 f(p) { 1326 f(p) {
1427 return const C<A, A>(); 1327 return const C<A, A>();
1428 }'''); 1328 }''');
1429 computeLibrarySourceErrors(source);
1430 assertErrors( 1329 assertErrors(
1431 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]); 1330 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]);
1432 verify([source]); 1331 verify([source]);
1433 } 1332 }
1434 1333
1435 void test_constWithNonConst() { 1334 void test_constWithNonConst() {
1436 Source source = addSource(r''' 1335 Source source = addSource(r'''
1437 class T { 1336 class T {
1438 T(a, b, {c, d}) {} 1337 T(a, b, {c, d}) {}
1439 } 1338 }
1440 f() { return const T(0, 1, c: 2, d: 3); }'''); 1339 f() { return const T(0, 1, c: 2, d: 3); }''');
1441 computeLibrarySourceErrors(source);
1442 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]); 1340 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]);
1443 verify([source]); 1341 verify([source]);
1444 } 1342 }
1445 1343
1446 void test_constWithNonConst_with() { 1344 void test_constWithNonConst_with() {
1447 Source source = addSource(r''' 1345 Source source = addSource(r'''
1448 class B { 1346 class B {
1449 const B(); 1347 const B();
1450 } 1348 }
1451 class C = B with M; 1349 class C = B with M;
1452 class M {} 1350 class M {}
1453 const x = const C(); 1351 const x = const C();
1454 main() { 1352 main() {
1455 print(x); 1353 print(x);
1456 } 1354 }
1457 '''); 1355 ''');
1458 computeLibrarySourceErrors(source);
1459 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]); 1356 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]);
1460 verify([source]); 1357 verify([source]);
1461 } 1358 }
1462 1359
1463 void test_constWithNonConstantArgument_annotation() { 1360 void test_constWithNonConstantArgument_annotation() {
1464 Source source = addSource(r''' 1361 Source source = addSource(r'''
1465 class A { 1362 class A {
1466 const A(int p); 1363 const A(int p);
1467 } 1364 }
1468 var v = 42; 1365 var v = 42;
1469 @A(v) 1366 @A(v)
1470 main() { 1367 main() {
1471 }'''); 1368 }''');
1472 computeLibrarySourceErrors(source);
1473 assertErrors( 1369 assertErrors(
1474 source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT]); 1370 source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT]);
1475 verify([source]); 1371 verify([source]);
1476 } 1372 }
1477 1373
1478 void test_constWithNonConstantArgument_instanceCreation() { 1374 void test_constWithNonConstantArgument_instanceCreation() {
1479 Source source = addSource(r''' 1375 Source source = addSource(r'''
1480 class A { 1376 class A {
1481 const A(a); 1377 const A(a);
1482 } 1378 }
1483 f(p) { return const A(p); }'''); 1379 f(p) { return const A(p); }''');
1484 computeLibrarySourceErrors(source);
1485 // TODO(paulberry): the error INVALID_CONSTAT is redundant and ought to be 1380 // TODO(paulberry): the error INVALID_CONSTAT is redundant and ought to be
1486 // suppressed. 1381 // suppressed.
1487 assertErrors(source, [ 1382 assertErrors(source, [
1488 CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT, 1383 CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT,
1489 CompileTimeErrorCode.INVALID_CONSTANT 1384 CompileTimeErrorCode.INVALID_CONSTANT
1490 ]); 1385 ]);
1491 verify([source]); 1386 verify([source]);
1492 } 1387 }
1493 1388
1494 void test_constWithNonType() { 1389 void test_constWithNonType() {
1495 Source source = addSource(r''' 1390 Source source = addSource(r'''
1496 int A; 1391 int A;
1497 f() { 1392 f() {
1498 return const A(); 1393 return const A();
1499 }'''); 1394 }''');
1500 computeLibrarySourceErrors(source);
1501 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); 1395 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]);
1502 verify([source]); 1396 verify([source]);
1503 } 1397 }
1504 1398
1505 void test_constWithNonType_fromLibrary() { 1399 void test_constWithNonType_fromLibrary() {
1506 Source source1 = addNamedSource("/lib.dart", ""); 1400 Source source1 = addNamedSource("/lib.dart", "");
1507 Source source2 = addNamedSource( 1401 Source source2 = addNamedSource(
1508 "/lib2.dart", 1402 "/lib2.dart",
1509 r''' 1403 r'''
1510 import 'lib.dart' as lib; 1404 import 'lib.dart' as lib;
1511 void f() { 1405 void f() {
1512 const lib.A(); 1406 const lib.A();
1513 }'''); 1407 }''');
1514 computeLibrarySourceErrors(source1);
1515 computeLibrarySourceErrors(source2);
1516 assertErrors(source2, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); 1408 assertErrors(source2, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]);
1517 verify([source1]); 1409 verify([source1]);
1518 } 1410 }
1519 1411
1520 void test_constWithTypeParameters_direct() { 1412 void test_constWithTypeParameters_direct() {
1521 Source source = addSource(r''' 1413 Source source = addSource(r'''
1522 class A<T> { 1414 class A<T> {
1523 static const V = const A<T>(); 1415 static const V = const A<T>();
1524 const A(); 1416 const A();
1525 }'''); 1417 }''');
1526 computeLibrarySourceErrors(source);
1527 assertErrors(source, [ 1418 assertErrors(source, [
1528 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 1419 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS,
1529 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC 1420 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC
1530 ]); 1421 ]);
1531 verify([source]); 1422 verify([source]);
1532 } 1423 }
1533 1424
1534 void test_constWithTypeParameters_indirect() { 1425 void test_constWithTypeParameters_indirect() {
1535 Source source = addSource(r''' 1426 Source source = addSource(r'''
1536 class A<T> { 1427 class A<T> {
1537 static const V = const A<List<T>>(); 1428 static const V = const A<List<T>>();
1538 const A(); 1429 const A();
1539 }'''); 1430 }''');
1540 computeLibrarySourceErrors(source);
1541 assertErrors(source, [ 1431 assertErrors(source, [
1542 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, 1432 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS,
1543 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC 1433 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC
1544 ]); 1434 ]);
1545 verify([source]); 1435 verify([source]);
1546 } 1436 }
1547 1437
1548 void test_constWithUndefinedConstructor() { 1438 void test_constWithUndefinedConstructor() {
1549 Source source = addSource(r''' 1439 Source source = addSource(r'''
1550 class A { 1440 class A {
1551 const A(); 1441 const A();
1552 } 1442 }
1553 f() { 1443 f() {
1554 return const A.noSuchConstructor(); 1444 return const A.noSuchConstructor();
1555 }'''); 1445 }''');
1556 computeLibrarySourceErrors(source);
1557 assertErrors( 1446 assertErrors(
1558 source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]); 1447 source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]);
1559 // no verify(), 'noSuchConstructor' is not resolved 1448 // no verify(), 'noSuchConstructor' is not resolved
1560 } 1449 }
1561 1450
1562 void test_constWithUndefinedConstructorDefault() { 1451 void test_constWithUndefinedConstructorDefault() {
1563 Source source = addSource(r''' 1452 Source source = addSource(r'''
1564 class A { 1453 class A {
1565 const A.name(); 1454 const A.name();
1566 } 1455 }
1567 f() { 1456 f() {
1568 return const A(); 1457 return const A();
1569 }'''); 1458 }''');
1570 computeLibrarySourceErrors(source);
1571 assertErrors(source, 1459 assertErrors(source,
1572 [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]); 1460 [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]);
1573 verify([source]); 1461 verify([source]);
1574 } 1462 }
1575 1463
1576 void test_defaultValueInFunctionTypeAlias() { 1464 void test_defaultValueInFunctionTypeAlias() {
1577 Source source = addSource("typedef F([x = 0]);"); 1465 Source source = addSource("typedef F([x = 0]);");
1578 computeLibrarySourceErrors(source);
1579 assertErrors( 1466 assertErrors(
1580 source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]); 1467 source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]);
1581 verify([source]); 1468 verify([source]);
1582 } 1469 }
1583 1470
1584 void test_defaultValueInFunctionTypedParameter_named() { 1471 void test_defaultValueInFunctionTypedParameter_named() {
1585 Source source = addSource("f(g({p: null})) {}"); 1472 Source source = addSource("f(g({p: null})) {}");
1586 computeLibrarySourceErrors(source);
1587 assertErrors(source, 1473 assertErrors(source,
1588 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]); 1474 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]);
1589 verify([source]); 1475 verify([source]);
1590 } 1476 }
1591 1477
1592 void test_defaultValueInFunctionTypedParameter_optional() { 1478 void test_defaultValueInFunctionTypedParameter_optional() {
1593 Source source = addSource("f(g([p = null])) {}"); 1479 Source source = addSource("f(g([p = null])) {}");
1594 computeLibrarySourceErrors(source);
1595 assertErrors(source, 1480 assertErrors(source,
1596 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]); 1481 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]);
1597 verify([source]); 1482 verify([source]);
1598 } 1483 }
1599 1484
1600 void test_defaultValueInRedirectingFactoryConstructor() { 1485 void test_defaultValueInRedirectingFactoryConstructor() {
1601 Source source = addSource(r''' 1486 Source source = addSource(r'''
1602 class A { 1487 class A {
1603 factory A([int x = 0]) = B; 1488 factory A([int x = 0]) = B;
1604 } 1489 }
1605 1490
1606 class B implements A { 1491 class B implements A {
1607 B([int x = 1]) {} 1492 B([int x = 1]) {}
1608 }'''); 1493 }''');
1609 computeLibrarySourceErrors(source);
1610 assertErrors(source, [ 1494 assertErrors(source, [
1611 CompileTimeErrorCode.DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR 1495 CompileTimeErrorCode.DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR
1612 ]); 1496 ]);
1613 verify([source]); 1497 verify([source]);
1614 } 1498 }
1615 1499
1616 void test_duplicateConstructorName_named() { 1500 void test_duplicateConstructorName_named() {
1617 Source source = addSource(r''' 1501 Source source = addSource(r'''
1618 class A { 1502 class A {
1619 A.a() {} 1503 A.a() {}
1620 A.a() {} 1504 A.a() {}
1621 }'''); 1505 }''');
1622 computeLibrarySourceErrors(source);
1623 assertErrors(source, [ 1506 assertErrors(source, [
1624 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, 1507 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME,
1625 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME 1508 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME
1626 ]); 1509 ]);
1627 verify([source]); 1510 verify([source]);
1628 } 1511 }
1629 1512
1630 void test_duplicateConstructorName_unnamed() { 1513 void test_duplicateConstructorName_unnamed() {
1631 Source source = addSource(r''' 1514 Source source = addSource(r'''
1632 class A { 1515 class A {
1633 A() {} 1516 A() {}
1634 A() {} 1517 A() {}
1635 }'''); 1518 }''');
1636 computeLibrarySourceErrors(source);
1637 assertErrors(source, [ 1519 assertErrors(source, [
1638 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, 1520 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT,
1639 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT 1521 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT
1640 ]); 1522 ]);
1641 verify([source]); 1523 verify([source]);
1642 } 1524 }
1643 1525
1644 void test_duplicateDefinition_acrossLibraries() { 1526 void test_duplicateDefinition_acrossLibraries() {
1645 Source librarySource = addNamedSource( 1527 Source librarySource = addNamedSource(
1646 "/lib.dart", 1528 "/lib.dart",
1647 r''' 1529 r'''
1648 library lib; 1530 library lib;
1649 1531
1650 part 'a.dart'; 1532 part 'a.dart';
1651 part 'b.dart';'''); 1533 part 'b.dart';''');
1652 Source sourceA = addNamedSource( 1534 Source sourceA = addNamedSource(
1653 "/a.dart", 1535 "/a.dart",
1654 r''' 1536 r'''
1655 part of lib; 1537 part of lib;
1656 1538
1657 class A {}'''); 1539 class A {}''');
1658 Source sourceB = addNamedSource( 1540 Source sourceB = addNamedSource(
1659 "/b.dart", 1541 "/b.dart",
1660 r''' 1542 r'''
1661 part of lib; 1543 part of lib;
1662 1544
1663 class A {}'''); 1545 class A {}''');
1664 computeLibrarySourceErrors(librarySource); 1546 assertNoErrors(librarySource);
1665 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1547 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1666 assertNoErrors(librarySource);
1667 verify([librarySource, sourceA, sourceB]); 1548 verify([librarySource, sourceA, sourceB]);
1668 } 1549 }
1669 1550
1670 void test_duplicateDefinition_catch() { 1551 void test_duplicateDefinition_catch() {
1671 Source source = addSource(r''' 1552 Source source = addSource(r'''
1672 main() { 1553 main() {
1673 try {} catch (e, e) {} 1554 try {} catch (e, e) {}
1674 }'''); 1555 }''');
1675 computeLibrarySourceErrors(source);
1676 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1556 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1677 verify([source]); 1557 verify([source]);
1678 } 1558 }
1679 1559
1680 void test_duplicateDefinition_classMembers_fields() { 1560 void test_duplicateDefinition_classMembers_fields() {
1681 Source source = addSource(r''' 1561 Source source = addSource(r'''
1682 class A { 1562 class A {
1683 int a; 1563 int a;
1684 int a; 1564 int a;
1685 }'''); 1565 }''');
1686 computeLibrarySourceErrors(source);
1687 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1566 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1688 verify([source]); 1567 verify([source]);
1689 } 1568 }
1690 1569
1691 void test_duplicateDefinition_classMembers_fields_oneStatic() { 1570 void test_duplicateDefinition_classMembers_fields_oneStatic() {
1692 Source source = addSource(r''' 1571 Source source = addSource(r'''
1693 class A { 1572 class A {
1694 int x; 1573 int x;
1695 static int x; 1574 static int x;
1696 }'''); 1575 }''');
1697 computeLibrarySourceErrors(source);
1698 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1576 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1699 verify([source]); 1577 verify([source]);
1700 } 1578 }
1701 1579
1702 void test_duplicateDefinition_classMembers_methods() { 1580 void test_duplicateDefinition_classMembers_methods() {
1703 Source source = addSource(r''' 1581 Source source = addSource(r'''
1704 class A { 1582 class A {
1705 m() {} 1583 m() {}
1706 m() {} 1584 m() {}
1707 }'''); 1585 }''');
1708 computeLibrarySourceErrors(source);
1709 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1586 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1710 verify([source]); 1587 verify([source]);
1711 } 1588 }
1712 1589
1713 void test_duplicateDefinition_inPart() { 1590 void test_duplicateDefinition_inPart() {
1714 Source librarySource = addNamedSource( 1591 Source librarySource = addNamedSource(
1715 "/lib.dart", 1592 "/lib.dart",
1716 r''' 1593 r'''
1717 library test; 1594 library test;
1718 part 'a.dart'; 1595 part 'a.dart';
1719 class A {}'''); 1596 class A {}''');
1720 Source sourceA = addNamedSource( 1597 Source sourceA = addNamedSource(
1721 "/a.dart", 1598 "/a.dart",
1722 r''' 1599 r'''
1723 part of test; 1600 part of test;
1724 class A {}'''); 1601 class A {}''');
1725 computeLibrarySourceErrors(librarySource); 1602 assertNoErrors(librarySource);
1726 assertErrors(sourceA, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1603 assertErrors(sourceA, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1727 assertNoErrors(librarySource);
1728 verify([librarySource, sourceA]); 1604 verify([librarySource, sourceA]);
1729 } 1605 }
1730 1606
1731 void test_duplicateDefinition_locals_inCase() { 1607 void test_duplicateDefinition_locals_inCase() {
1732 Source source = addSource(r''' 1608 Source source = addSource(r'''
1733 main() { 1609 main() {
1734 switch(1) { 1610 switch(1) {
1735 case 1: 1611 case 1:
1736 var a; 1612 var a;
1737 var a; 1613 var a;
1738 } 1614 }
1739 }'''); 1615 }''');
1740 computeLibrarySourceErrors(source);
1741 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1616 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1742 verify([source]); 1617 verify([source]);
1743 } 1618 }
1744 1619
1745 void test_duplicateDefinition_locals_inFunctionBlock() { 1620 void test_duplicateDefinition_locals_inFunctionBlock() {
1746 Source source = addSource(r''' 1621 Source source = addSource(r'''
1747 main() { 1622 main() {
1748 int m = 0; 1623 int m = 0;
1749 m(a) {} 1624 m(a) {}
1750 }'''); 1625 }''');
1751 computeLibrarySourceErrors(source);
1752 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1626 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1753 verify([source]); 1627 verify([source]);
1754 } 1628 }
1755 1629
1756 void test_duplicateDefinition_locals_inIf() { 1630 void test_duplicateDefinition_locals_inIf() {
1757 Source source = addSource(r''' 1631 Source source = addSource(r'''
1758 main(int p) { 1632 main(int p) {
1759 if (p != 0) { 1633 if (p != 0) {
1760 var a; 1634 var a;
1761 var a; 1635 var a;
1762 } 1636 }
1763 }'''); 1637 }''');
1764 computeLibrarySourceErrors(source);
1765 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1638 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1766 verify([source]); 1639 verify([source]);
1767 } 1640 }
1768 1641
1769 void test_duplicateDefinition_locals_inMethodBlock() { 1642 void test_duplicateDefinition_locals_inMethodBlock() {
1770 Source source = addSource(r''' 1643 Source source = addSource(r'''
1771 class A { 1644 class A {
1772 m() { 1645 m() {
1773 int a; 1646 int a;
1774 int a; 1647 int a;
1775 } 1648 }
1776 }'''); 1649 }''');
1777 computeLibrarySourceErrors(source);
1778 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1650 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1779 verify([source]); 1651 verify([source]);
1780 } 1652 }
1781 1653
1782 void test_duplicateDefinition_parameters_inConstructor() { 1654 void test_duplicateDefinition_parameters_inConstructor() {
1783 Source source = addSource(r''' 1655 Source source = addSource(r'''
1784 class A { 1656 class A {
1785 int a; 1657 int a;
1786 A(int a, this.a); 1658 A(int a, this.a);
1787 }'''); 1659 }''');
1788 computeLibrarySourceErrors(source);
1789 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1660 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1790 verify([source]); 1661 verify([source]);
1791 } 1662 }
1792 1663
1793 void test_duplicateDefinition_parameters_inFunctionTypeAlias() { 1664 void test_duplicateDefinition_parameters_inFunctionTypeAlias() {
1794 Source source = addSource(r''' 1665 Source source = addSource(r'''
1795 typedef F(int a, double a); 1666 typedef F(int a, double a);
1796 '''); 1667 ''');
1797 computeLibrarySourceErrors(source);
1798 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1668 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1799 verify([source]); 1669 verify([source]);
1800 } 1670 }
1801 1671
1802 void test_duplicateDefinition_parameters_inLocalFunction() { 1672 void test_duplicateDefinition_parameters_inLocalFunction() {
1803 Source source = addSource(r''' 1673 Source source = addSource(r'''
1804 main() { 1674 main() {
1805 f(int a, double a) { 1675 f(int a, double a) {
1806 }; 1676 };
1807 }'''); 1677 }''');
1808 computeLibrarySourceErrors(source);
1809 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1678 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1810 verify([source]); 1679 verify([source]);
1811 } 1680 }
1812 1681
1813 void test_duplicateDefinition_parameters_inMethod() { 1682 void test_duplicateDefinition_parameters_inMethod() {
1814 Source source = addSource(r''' 1683 Source source = addSource(r'''
1815 class A { 1684 class A {
1816 m(int a, double a) { 1685 m(int a, double a) {
1817 } 1686 }
1818 }'''); 1687 }''');
1819 computeLibrarySourceErrors(source);
1820 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1688 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1821 verify([source]); 1689 verify([source]);
1822 } 1690 }
1823 1691
1824 void test_duplicateDefinition_parameters_inTopLevelFunction() { 1692 void test_duplicateDefinition_parameters_inTopLevelFunction() {
1825 Source source = addSource(r''' 1693 Source source = addSource(r'''
1826 f(int a, double a) { 1694 f(int a, double a) {
1827 }'''); 1695 }''');
1828 computeLibrarySourceErrors(source);
1829 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1696 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1830 verify([source]); 1697 verify([source]);
1831 } 1698 }
1832 1699
1833 void test_duplicateDefinition_typeParameters() { 1700 void test_duplicateDefinition_typeParameters() {
1834 Source source = addSource(r''' 1701 Source source = addSource(r'''
1835 class A<T, T> { 1702 class A<T, T> {
1836 }'''); 1703 }''');
1837 computeLibrarySourceErrors(source);
1838 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1704 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1839 verify([source]); 1705 verify([source]);
1840 } 1706 }
1841 1707
1842 void test_duplicateDefinitionInheritance_instanceGetter_staticGetter() { 1708 void test_duplicateDefinitionInheritance_instanceGetter_staticGetter() {
1843 Source source = addSource(r''' 1709 Source source = addSource(r'''
1844 class A { 1710 class A {
1845 int get x => 0; 1711 int get x => 0;
1846 } 1712 }
1847 class B extends A { 1713 class B extends A {
1848 static int get x => 0; 1714 static int get x => 0;
1849 }'''); 1715 }''');
1850 computeLibrarySourceErrors(source);
1851 assertErrors( 1716 assertErrors(
1852 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1717 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1853 verify([source]); 1718 verify([source]);
1854 } 1719 }
1855 1720
1856 void 1721 void
1857 test_duplicateDefinitionInheritance_instanceGetterAbstract_staticGetter() { 1722 test_duplicateDefinitionInheritance_instanceGetterAbstract_staticGetter() {
1858 Source source = addSource(r''' 1723 Source source = addSource(r'''
1859 abstract class A { 1724 abstract class A {
1860 int get x; 1725 int get x;
1861 } 1726 }
1862 class B extends A { 1727 class B extends A {
1863 static int get x => 0; 1728 static int get x => 0;
1864 }'''); 1729 }''');
1865 computeLibrarySourceErrors(source);
1866 assertErrors( 1730 assertErrors(
1867 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1731 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1868 verify([source]); 1732 verify([source]);
1869 } 1733 }
1870 1734
1871 void test_duplicateDefinitionInheritance_instanceMethod_staticMethod() { 1735 void test_duplicateDefinitionInheritance_instanceMethod_staticMethod() {
1872 Source source = addSource(r''' 1736 Source source = addSource(r'''
1873 class A { 1737 class A {
1874 x() {} 1738 x() {}
1875 } 1739 }
1876 class B extends A { 1740 class B extends A {
1877 static x() {} 1741 static x() {}
1878 }'''); 1742 }''');
1879 computeLibrarySourceErrors(source);
1880 assertErrors( 1743 assertErrors(
1881 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1744 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1882 verify([source]); 1745 verify([source]);
1883 } 1746 }
1884 1747
1885 void 1748 void
1886 test_duplicateDefinitionInheritance_instanceMethodAbstract_staticMethod() { 1749 test_duplicateDefinitionInheritance_instanceMethodAbstract_staticMethod() {
1887 Source source = addSource(r''' 1750 Source source = addSource(r'''
1888 abstract class A { 1751 abstract class A {
1889 x(); 1752 x();
1890 } 1753 }
1891 abstract class B extends A { 1754 abstract class B extends A {
1892 static x() {} 1755 static x() {}
1893 }'''); 1756 }''');
1894 computeLibrarySourceErrors(source);
1895 assertErrors( 1757 assertErrors(
1896 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1758 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1897 verify([source]); 1759 verify([source]);
1898 } 1760 }
1899 1761
1900 void test_duplicateDefinitionInheritance_instanceSetter_staticSetter() { 1762 void test_duplicateDefinitionInheritance_instanceSetter_staticSetter() {
1901 Source source = addSource(r''' 1763 Source source = addSource(r'''
1902 class A { 1764 class A {
1903 set x(value) {} 1765 set x(value) {}
1904 } 1766 }
1905 class B extends A { 1767 class B extends A {
1906 static set x(value) {} 1768 static set x(value) {}
1907 }'''); 1769 }''');
1908 computeLibrarySourceErrors(source);
1909 assertErrors( 1770 assertErrors(
1910 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1771 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1911 verify([source]); 1772 verify([source]);
1912 } 1773 }
1913 1774
1914 void 1775 void
1915 test_duplicateDefinitionInheritance_instanceSetterAbstract_staticSetter() { 1776 test_duplicateDefinitionInheritance_instanceSetterAbstract_staticSetter() {
1916 Source source = addSource(r''' 1777 Source source = addSource(r'''
1917 abstract class A { 1778 abstract class A {
1918 set x(value); 1779 set x(value);
1919 } 1780 }
1920 class B extends A { 1781 class B extends A {
1921 static set x(value) {} 1782 static set x(value) {}
1922 }'''); 1783 }''');
1923 computeLibrarySourceErrors(source);
1924 assertErrors( 1784 assertErrors(
1925 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1785 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1926 verify([source]); 1786 verify([source]);
1927 } 1787 }
1928 1788
1929 void test_duplicateNamedArgument() { 1789 void test_duplicateNamedArgument() {
1930 Source source = addSource(r''' 1790 Source source = addSource(r'''
1931 f({a, b}) {} 1791 f({a, b}) {}
1932 main() { 1792 main() {
1933 f(a: 1, a: 2); 1793 f(a: 1, a: 2);
1934 }'''); 1794 }''');
1935 computeLibrarySourceErrors(source);
1936 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT]); 1795 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT]);
1937 verify([source]); 1796 verify([source]);
1938 } 1797 }
1939 1798
1940 void test_duplicatePart_sameSource() { 1799 void test_duplicatePart_sameSource() {
1941 addNamedSource('/part.dart', 'part of lib;'); 1800 addNamedSource('/part.dart', 'part of lib;');
1942 Source source = addSource(r''' 1801 Source source = addSource(r'''
1943 library lib; 1802 library lib;
1944 part 'part.dart'; 1803 part 'part.dart';
1945 part 'foo/../part.dart'; 1804 part 'foo/../part.dart';
1946 '''); 1805 ''');
1947 computeLibrarySourceErrors(source);
1948 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_PART]); 1806 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_PART]);
1949 verify([source]); 1807 verify([source]);
1950 } 1808 }
1951 1809
1952 void test_duplicatePart_sameUri() { 1810 void test_duplicatePart_sameUri() {
1953 addNamedSource('/part.dart', 'part of lib;'); 1811 addNamedSource('/part.dart', 'part of lib;');
1954 Source source = addSource(r''' 1812 Source source = addSource(r'''
1955 library lib; 1813 library lib;
1956 part 'part.dart'; 1814 part 'part.dart';
1957 part 'part.dart'; 1815 part 'part.dart';
1958 '''); 1816 ''');
1959 computeLibrarySourceErrors(source);
1960 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_PART]); 1817 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_PART]);
1961 verify([source]); 1818 verify([source]);
1962 } 1819 }
1963 1820
1964 void test_exportInternalLibrary() { 1821 void test_exportInternalLibrary() {
1965 Source source = addSource("export 'dart:_interceptors';"); 1822 Source source = addSource("export 'dart:_interceptors';");
1966 computeLibrarySourceErrors(source);
1967 assertErrors(source, [CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY]); 1823 assertErrors(source, [CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY]);
1968 verify([source]); 1824 verify([source]);
1969 } 1825 }
1970 1826
1971 void test_exportOfNonLibrary() { 1827 void test_exportOfNonLibrary() {
1972 Source source = addSource(r''' 1828 Source source = addSource(r'''
1973 library L; 1829 library L;
1974 export 'lib1.dart';'''); 1830 export 'lib1.dart';''');
1975 addNamedSource("/lib1.dart", "part of lib;"); 1831 addNamedSource("/lib1.dart", "part of lib;");
1976 computeLibrarySourceErrors(source);
1977 assertErrors(source, [CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); 1832 assertErrors(source, [CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]);
1978 verify([source]); 1833 verify([source]);
1979 } 1834 }
1980 1835
1981 void test_extendsDeferredClass() { 1836 void test_extendsDeferredClass() {
1982 resolveWithErrors(<String>[ 1837 resolveWithErrors(<String>[
1983 r''' 1838 r'''
1984 library lib1; 1839 library lib1;
1985 class A {}''', 1840 class A {}''',
1986 r''' 1841 r'''
(...skipping 15 matching lines...) Expand all
2002 import 'lib1.dart' deferred as a; 1857 import 'lib1.dart' deferred as a;
2003 class M {} 1858 class M {}
2004 class C = a.A with M;''' 1859 class C = a.A with M;'''
2005 ], <ErrorCode>[ 1860 ], <ErrorCode>[
2006 CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS 1861 CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS
2007 ]); 1862 ]);
2008 } 1863 }
2009 1864
2010 void test_extendsDisallowedClass_class_bool() { 1865 void test_extendsDisallowedClass_class_bool() {
2011 Source source = addSource("class A extends bool {}"); 1866 Source source = addSource("class A extends bool {}");
2012 computeLibrarySourceErrors(source);
2013 assertErrors(source, [ 1867 assertErrors(source, [
2014 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1868 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
2015 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 1869 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
2016 ]); 1870 ]);
2017 verify([source]); 1871 verify([source]);
2018 } 1872 }
2019 1873
2020 void test_extendsDisallowedClass_class_double() { 1874 void test_extendsDisallowedClass_class_double() {
2021 Source source = addSource("class A extends double {}"); 1875 Source source = addSource("class A extends double {}");
2022 computeLibrarySourceErrors(source);
2023 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1876 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
2024 verify([source]); 1877 verify([source]);
2025 } 1878 }
2026 1879
2027 void test_extendsDisallowedClass_class_int() { 1880 void test_extendsDisallowedClass_class_int() {
2028 Source source = addSource("class A extends int {}"); 1881 Source source = addSource("class A extends int {}");
2029 computeLibrarySourceErrors(source);
2030 assertErrors(source, [ 1882 assertErrors(source, [
2031 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1883 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
2032 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 1884 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
2033 ]); 1885 ]);
2034 verify([source]); 1886 verify([source]);
2035 } 1887 }
2036 1888
2037 void test_extendsDisallowedClass_class_Null() { 1889 void test_extendsDisallowedClass_class_Null() {
2038 Source source = addSource("class A extends Null {}"); 1890 Source source = addSource("class A extends Null {}");
2039 computeLibrarySourceErrors(source);
2040 assertErrors(source, [ 1891 assertErrors(source, [
2041 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1892 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
2042 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 1893 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
2043 ]); 1894 ]);
2044 verify([source]); 1895 verify([source]);
2045 } 1896 }
2046 1897
2047 void test_extendsDisallowedClass_class_num() { 1898 void test_extendsDisallowedClass_class_num() {
2048 Source source = addSource("class A extends num {}"); 1899 Source source = addSource("class A extends num {}");
2049 computeLibrarySourceErrors(source);
2050 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1900 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
2051 verify([source]); 1901 verify([source]);
2052 } 1902 }
2053 1903
2054 void test_extendsDisallowedClass_class_String() { 1904 void test_extendsDisallowedClass_class_String() {
2055 Source source = addSource("class A extends String {}"); 1905 Source source = addSource("class A extends String {}");
2056 computeLibrarySourceErrors(source);
2057 assertErrors(source, [ 1906 assertErrors(source, [
2058 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 1907 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
2059 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 1908 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
2060 ]); 1909 ]);
2061 verify([source]); 1910 verify([source]);
2062 } 1911 }
2063 1912
2064 void test_extendsDisallowedClass_classTypeAlias_bool() { 1913 void test_extendsDisallowedClass_classTypeAlias_bool() {
2065 Source source = addSource(r''' 1914 Source source = addSource(r'''
2066 class M {} 1915 class M {}
2067 class C = bool with M;'''); 1916 class C = bool with M;''');
2068 computeLibrarySourceErrors(source);
2069 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1917 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
2070 verify([source]); 1918 verify([source]);
2071 } 1919 }
2072 1920
2073 void test_extendsDisallowedClass_classTypeAlias_double() { 1921 void test_extendsDisallowedClass_classTypeAlias_double() {
2074 Source source = addSource(r''' 1922 Source source = addSource(r'''
2075 class M {} 1923 class M {}
2076 class C = double with M;'''); 1924 class C = double with M;''');
2077 computeLibrarySourceErrors(source);
2078 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1925 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
2079 verify([source]); 1926 verify([source]);
2080 } 1927 }
2081 1928
2082 void test_extendsDisallowedClass_classTypeAlias_int() { 1929 void test_extendsDisallowedClass_classTypeAlias_int() {
2083 Source source = addSource(r''' 1930 Source source = addSource(r'''
2084 class M {} 1931 class M {}
2085 class C = int with M;'''); 1932 class C = int with M;''');
2086 computeLibrarySourceErrors(source);
2087 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1933 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
2088 verify([source]); 1934 verify([source]);
2089 } 1935 }
2090 1936
2091 void test_extendsDisallowedClass_classTypeAlias_Null() { 1937 void test_extendsDisallowedClass_classTypeAlias_Null() {
2092 Source source = addSource(r''' 1938 Source source = addSource(r'''
2093 class M {} 1939 class M {}
2094 class C = Null with M;'''); 1940 class C = Null with M;''');
2095 computeLibrarySourceErrors(source);
2096 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1941 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
2097 verify([source]); 1942 verify([source]);
2098 } 1943 }
2099 1944
2100 void test_extendsDisallowedClass_classTypeAlias_num() { 1945 void test_extendsDisallowedClass_classTypeAlias_num() {
2101 Source source = addSource(r''' 1946 Source source = addSource(r'''
2102 class M {} 1947 class M {}
2103 class C = num with M;'''); 1948 class C = num with M;''');
2104 computeLibrarySourceErrors(source);
2105 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1949 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
2106 verify([source]); 1950 verify([source]);
2107 } 1951 }
2108 1952
2109 void test_extendsDisallowedClass_classTypeAlias_String() { 1953 void test_extendsDisallowedClass_classTypeAlias_String() {
2110 Source source = addSource(r''' 1954 Source source = addSource(r'''
2111 class M {} 1955 class M {}
2112 class C = String with M;'''); 1956 class C = String with M;''');
2113 computeLibrarySourceErrors(source);
2114 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); 1957 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
2115 verify([source]); 1958 verify([source]);
2116 } 1959 }
2117 1960
2118 void test_extendsEnum() { 1961 void test_extendsEnum() {
2119 Source source = addSource(r''' 1962 Source source = addSource(r'''
2120 enum E { ONE } 1963 enum E { ONE }
2121 class A extends E {}'''); 1964 class A extends E {}''');
2122 computeLibrarySourceErrors(source);
2123 assertErrors(source, [CompileTimeErrorCode.EXTENDS_ENUM]); 1965 assertErrors(source, [CompileTimeErrorCode.EXTENDS_ENUM]);
2124 verify([source]); 1966 verify([source]);
2125 } 1967 }
2126 1968
2127 void test_extendsNonClass_class() { 1969 void test_extendsNonClass_class() {
2128 Source source = addSource(r''' 1970 Source source = addSource(r'''
2129 int A; 1971 int A;
2130 class B extends A {}'''); 1972 class B extends A {}''');
2131 computeLibrarySourceErrors(source);
2132 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); 1973 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]);
2133 verify([source]); 1974 verify([source]);
2134 } 1975 }
2135 1976
2136 void test_extendsNonClass_dynamic() { 1977 void test_extendsNonClass_dynamic() {
2137 Source source = addSource("class B extends dynamic {}"); 1978 Source source = addSource("class B extends dynamic {}");
2138 computeLibrarySourceErrors(source);
2139 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); 1979 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]);
2140 verify([source]); 1980 verify([source]);
2141 } 1981 }
2142 1982
2143 void test_extraPositionalArguments_const() { 1983 void test_extraPositionalArguments_const() {
2144 Source source = addSource(r''' 1984 Source source = addSource(r'''
2145 class A { 1985 class A {
2146 const A(); 1986 const A();
2147 } 1987 }
2148 main() { 1988 main() {
2149 const A(0); 1989 const A(0);
2150 }'''); 1990 }''');
2151 computeLibrarySourceErrors(source);
2152 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); 1991 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]);
2153 verify([source]); 1992 verify([source]);
2154 } 1993 }
2155 1994
2156 void test_extraPositionalArguments_const_super() { 1995 void test_extraPositionalArguments_const_super() {
2157 Source source = addSource(r''' 1996 Source source = addSource(r'''
2158 class A { 1997 class A {
2159 const A(); 1998 const A();
2160 } 1999 }
2161 class B extends A { 2000 class B extends A {
2162 const B() : super(0); 2001 const B() : super(0);
2163 }'''); 2002 }''');
2164 computeLibrarySourceErrors(source);
2165 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); 2003 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]);
2166 verify([source]); 2004 verify([source]);
2167 } 2005 }
2168 2006
2169 void test_fieldFormalParameter_assignedInInitializer() { 2007 void test_fieldFormalParameter_assignedInInitializer() {
2170 Source source = addSource(r''' 2008 Source source = addSource(r'''
2171 class A { 2009 class A {
2172 int x; 2010 int x;
2173 A(this.x) : x = 3 {} 2011 A(this.x) : x = 3 {}
2174 }'''); 2012 }''');
2175 computeLibrarySourceErrors(source);
2176 assertErrors(source, 2013 assertErrors(source,
2177 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); 2014 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]);
2178 verify([source]); 2015 verify([source]);
2179 } 2016 }
2180 2017
2181 void test_fieldInitializedByMultipleInitializers() { 2018 void test_fieldInitializedByMultipleInitializers() {
2182 Source source = addSource(r''' 2019 Source source = addSource(r'''
2183 class A { 2020 class A {
2184 int x; 2021 int x;
2185 A() : x = 0, x = 1 {} 2022 A() : x = 0, x = 1 {}
2186 }'''); 2023 }''');
2187 computeLibrarySourceErrors(source);
2188 assertErrors(source, 2024 assertErrors(source,
2189 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); 2025 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]);
2190 verify([source]); 2026 verify([source]);
2191 } 2027 }
2192 2028
2193 void test_fieldInitializedByMultipleInitializers_multipleInits() { 2029 void test_fieldInitializedByMultipleInitializers_multipleInits() {
2194 Source source = addSource(r''' 2030 Source source = addSource(r'''
2195 class A { 2031 class A {
2196 int x; 2032 int x;
2197 A() : x = 0, x = 1, x = 2 {} 2033 A() : x = 0, x = 1, x = 2 {}
2198 }'''); 2034 }''');
2199 computeLibrarySourceErrors(source);
2200 assertErrors(source, [ 2035 assertErrors(source, [
2201 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, 2036 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS,
2202 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS 2037 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS
2203 ]); 2038 ]);
2204 verify([source]); 2039 verify([source]);
2205 } 2040 }
2206 2041
2207 void test_fieldInitializedByMultipleInitializers_multipleNames() { 2042 void test_fieldInitializedByMultipleInitializers_multipleNames() {
2208 Source source = addSource(r''' 2043 Source source = addSource(r'''
2209 class A { 2044 class A {
2210 int x; 2045 int x;
2211 int y; 2046 int y;
2212 A() : x = 0, x = 1, y = 0, y = 1 {} 2047 A() : x = 0, x = 1, y = 0, y = 1 {}
2213 }'''); 2048 }''');
2214 computeLibrarySourceErrors(source);
2215 assertErrors(source, [ 2049 assertErrors(source, [
2216 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, 2050 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS,
2217 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS 2051 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS
2218 ]); 2052 ]);
2219 verify([source]); 2053 verify([source]);
2220 } 2054 }
2221 2055
2222 void test_fieldInitializedInParameterAndInitializer() { 2056 void test_fieldInitializedInParameterAndInitializer() {
2223 Source source = addSource(r''' 2057 Source source = addSource(r'''
2224 class A { 2058 class A {
2225 int x; 2059 int x;
2226 A(this.x) : x = 1 {} 2060 A(this.x) : x = 1 {}
2227 }'''); 2061 }''');
2228 computeLibrarySourceErrors(source);
2229 assertErrors(source, 2062 assertErrors(source,
2230 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); 2063 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]);
2231 verify([source]); 2064 verify([source]);
2232 } 2065 }
2233 2066
2234 void test_fieldInitializerFactoryConstructor() { 2067 void test_fieldInitializerFactoryConstructor() {
2235 Source source = addSource(r''' 2068 Source source = addSource(r'''
2236 class A { 2069 class A {
2237 int x; 2070 int x;
2238 factory A(this.x) => null; 2071 factory A(this.x) => null;
2239 }'''); 2072 }''');
2240 computeLibrarySourceErrors(source);
2241 assertErrors( 2073 assertErrors(
2242 source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR]); 2074 source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR]);
2243 verify([source]); 2075 verify([source]);
2244 } 2076 }
2245 2077
2246 void test_fieldInitializerOutsideConstructor() { 2078 void test_fieldInitializerOutsideConstructor() {
2247 // TODO(brianwilkerson) Fix the duplicate error messages. 2079 // TODO(brianwilkerson) Fix the duplicate error messages.
2248 Source source = addSource(r''' 2080 Source source = addSource(r'''
2249 class A { 2081 class A {
2250 int x; 2082 int x;
2251 m(this.x) {} 2083 m(this.x) {}
2252 }'''); 2084 }''');
2253 computeLibrarySourceErrors(source);
2254 assertErrors(source, [ 2085 assertErrors(source, [
2255 ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, 2086 ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR,
2256 CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR 2087 CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR
2257 ]); 2088 ]);
2258 verify([source]); 2089 verify([source]);
2259 } 2090 }
2260 2091
2261 void test_fieldInitializerOutsideConstructor_defaultParameter() { 2092 void test_fieldInitializerOutsideConstructor_defaultParameter() {
2262 Source source = addSource(r''' 2093 Source source = addSource(r'''
2263 class A { 2094 class A {
2264 int x; 2095 int x;
2265 m([this.x]) {} 2096 m([this.x]) {}
2266 }'''); 2097 }''');
2267 computeLibrarySourceErrors(source);
2268 assertErrors( 2098 assertErrors(
2269 source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); 2099 source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]);
2270 verify([source]); 2100 verify([source]);
2271 } 2101 }
2272 2102
2273 void test_fieldInitializerOutsideConstructor_inFunctionTypeParameter() { 2103 void test_fieldInitializerOutsideConstructor_inFunctionTypeParameter() {
2274 Source source = addSource(r''' 2104 Source source = addSource(r'''
2275 class A { 2105 class A {
2276 int x; 2106 int x;
2277 A(int p(this.x)); 2107 A(int p(this.x));
2278 }'''); 2108 }''');
2279 computeLibrarySourceErrors(source);
2280 assertErrors( 2109 assertErrors(
2281 source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); 2110 source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]);
2282 verify([source]); 2111 verify([source]);
2283 } 2112 }
2284 2113
2285 void test_fieldInitializerRedirectingConstructor_afterRedirection() { 2114 void test_fieldInitializerRedirectingConstructor_afterRedirection() {
2286 Source source = addSource(r''' 2115 Source source = addSource(r'''
2287 class A { 2116 class A {
2288 int x; 2117 int x;
2289 A.named() {} 2118 A.named() {}
2290 A() : this.named(), x = 42; 2119 A() : this.named(), x = 42;
2291 }'''); 2120 }''');
2292 computeLibrarySourceErrors(source);
2293 assertErrors(source, 2121 assertErrors(source,
2294 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); 2122 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]);
2295 verify([source]); 2123 verify([source]);
2296 } 2124 }
2297 2125
2298 void test_fieldInitializerRedirectingConstructor_beforeRedirection() { 2126 void test_fieldInitializerRedirectingConstructor_beforeRedirection() {
2299 Source source = addSource(r''' 2127 Source source = addSource(r'''
2300 class A { 2128 class A {
2301 int x; 2129 int x;
2302 A.named() {} 2130 A.named() {}
2303 A() : x = 42, this.named(); 2131 A() : x = 42, this.named();
2304 }'''); 2132 }''');
2305 computeLibrarySourceErrors(source);
2306 assertErrors(source, 2133 assertErrors(source,
2307 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); 2134 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]);
2308 verify([source]); 2135 verify([source]);
2309 } 2136 }
2310 2137
2311 void test_fieldInitializingFormalRedirectingConstructor() { 2138 void test_fieldInitializingFormalRedirectingConstructor() {
2312 Source source = addSource(r''' 2139 Source source = addSource(r'''
2313 class A { 2140 class A {
2314 int x; 2141 int x;
2315 A.named() {} 2142 A.named() {}
2316 A(this.x) : this.named(); 2143 A(this.x) : this.named();
2317 }'''); 2144 }''');
2318 computeLibrarySourceErrors(source);
2319 assertErrors(source, 2145 assertErrors(source,
2320 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); 2146 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]);
2321 verify([source]); 2147 verify([source]);
2322 } 2148 }
2323 2149
2324 void test_finalInitializedMultipleTimes_initializers() { 2150 void test_finalInitializedMultipleTimes_initializers() {
2325 Source source = addSource(r''' 2151 Source source = addSource(r'''
2326 class A { 2152 class A {
2327 final x; 2153 final x;
2328 A() : x = 0, x = 0 {} 2154 A() : x = 0, x = 0 {}
2329 }'''); 2155 }''');
2330 computeLibrarySourceErrors(source);
2331 assertErrors(source, 2156 assertErrors(source,
2332 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); 2157 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]);
2333 verify([source]); 2158 verify([source]);
2334 } 2159 }
2335 2160
2336 /** 2161 /**
2337 * This test doesn't test the FINAL_INITIALIZED_MULTIPLE_TIMES code, but tests the 2162 * This test doesn't test the FINAL_INITIALIZED_MULTIPLE_TIMES code, but tests the
2338 * FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER code instead. It is provided here to show 2163 * FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER code instead. It is provided here to show
2339 * coverage over all of the permutations of initializers in constructor declar ations. 2164 * coverage over all of the permutations of initializers in constructor declar ations.
2340 * 2165 *
2341 * Note: FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER covers a subset of 2166 * Note: FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER covers a subset of
2342 * FINAL_INITIALIZED_MULTIPLE_TIMES, since it more specific, we use it instead of the broader code 2167 * FINAL_INITIALIZED_MULTIPLE_TIMES, since it more specific, we use it instead of the broader code
2343 */ 2168 */
2344 void test_finalInitializedMultipleTimes_initializingFormal_initializer() { 2169 void test_finalInitializedMultipleTimes_initializingFormal_initializer() {
2345 Source source = addSource(r''' 2170 Source source = addSource(r'''
2346 class A { 2171 class A {
2347 final x; 2172 final x;
2348 A(this.x) : x = 0 {} 2173 A(this.x) : x = 0 {}
2349 }'''); 2174 }''');
2350 computeLibrarySourceErrors(source);
2351 assertErrors(source, 2175 assertErrors(source,
2352 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); 2176 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]);
2353 verify([source]); 2177 verify([source]);
2354 } 2178 }
2355 2179
2356 void test_finalInitializedMultipleTimes_initializingFormals() { 2180 void test_finalInitializedMultipleTimes_initializingFormals() {
2357 Source source = addSource(r''' 2181 Source source = addSource(r'''
2358 class A { 2182 class A {
2359 final x; 2183 final x;
2360 A(this.x, this.x) {} 2184 A(this.x, this.x) {}
2361 }'''); 2185 }''');
2362 computeLibrarySourceErrors(source);
2363 // TODO(brianwilkerson) There should only be one error here. 2186 // TODO(brianwilkerson) There should only be one error here.
2364 assertErrors(source, [ 2187 assertErrors(source, [
2365 CompileTimeErrorCode.DUPLICATE_DEFINITION, 2188 CompileTimeErrorCode.DUPLICATE_DEFINITION,
2366 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES 2189 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES
2367 ]); 2190 ]);
2368 verify([source]); 2191 verify([source]);
2369 } 2192 }
2370 2193
2371 void test_finalNotInitialized_instanceField_const_static() { 2194 void test_finalNotInitialized_instanceField_const_static() {
2372 Source source = addSource(r''' 2195 Source source = addSource(r'''
2373 class A { 2196 class A {
2374 static const F; 2197 static const F;
2375 }'''); 2198 }''');
2376 computeLibrarySourceErrors(source);
2377 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); 2199 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]);
2378 verify([source]); 2200 verify([source]);
2379 } 2201 }
2380 2202
2381 void test_finalNotInitialized_library_const() { 2203 void test_finalNotInitialized_library_const() {
2382 Source source = addSource("const F;"); 2204 Source source = addSource("const F;");
2383 computeLibrarySourceErrors(source);
2384 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); 2205 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]);
2385 verify([source]); 2206 verify([source]);
2386 } 2207 }
2387 2208
2388 void test_finalNotInitialized_local_const() { 2209 void test_finalNotInitialized_local_const() {
2389 Source source = addSource(r''' 2210 Source source = addSource(r'''
2390 f() { 2211 f() {
2391 const int x; 2212 const int x;
2392 }'''); 2213 }''');
2393 computeLibrarySourceErrors(source);
2394 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); 2214 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]);
2395 verify([source]); 2215 verify([source]);
2396 } 2216 }
2397 2217
2398 void test_fromEnvironment_bool_badArgs() { 2218 void test_fromEnvironment_bool_badArgs() {
2399 Source source = addSource(r''' 2219 Source source = addSource(r'''
2400 var b1 = const bool.fromEnvironment(1); 2220 var b1 = const bool.fromEnvironment(1);
2401 var b2 = const bool.fromEnvironment('x', defaultValue: 1);'''); 2221 var b2 = const bool.fromEnvironment('x', defaultValue: 1);''');
2402 computeLibrarySourceErrors(source);
2403 assertErrors(source, [ 2222 assertErrors(source, [
2404 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 2223 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
2405 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 2224 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
2406 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 2225 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
2407 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE 2226 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE
2408 ]); 2227 ]);
2409 verify([source]); 2228 verify([source]);
2410 } 2229 }
2411 2230
2412 void test_fromEnvironment_bool_badDefault_whenDefined() { 2231 void test_fromEnvironment_bool_badDefault_whenDefined() {
2413 // The type of the defaultValue needs to be correct even when the default 2232 // The type of the defaultValue needs to be correct even when the default
2414 // value isn't used (because the variable is defined in the environment). 2233 // value isn't used (because the variable is defined in the environment).
2415 analysisContext2.declaredVariables.define("x", "true"); 2234 analysisContext2.declaredVariables.define("x", "true");
2416 Source source = 2235 Source source =
2417 addSource("var b = const bool.fromEnvironment('x', defaultValue: 1);"); 2236 addSource("var b = const bool.fromEnvironment('x', defaultValue: 1);");
2418 computeLibrarySourceErrors(source);
2419 assertErrors(source, [ 2237 assertErrors(source, [
2420 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 2238 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
2421 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE 2239 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE
2422 ]); 2240 ]);
2423 verify([source]); 2241 verify([source]);
2424 } 2242 }
2425 2243
2426 void test_getterAndMethodWithSameName() { 2244 void test_getterAndMethodWithSameName() {
2427 Source source = addSource(r''' 2245 Source source = addSource(r'''
2428 class A { 2246 class A {
2429 x(y) {} 2247 x(y) {}
2430 get x => 0; 2248 get x => 0;
2431 }'''); 2249 }''');
2432 computeLibrarySourceErrors(source);
2433 assertErrors( 2250 assertErrors(
2434 source, [CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME]); 2251 source, [CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME]);
2435 verify([source]); 2252 verify([source]);
2436 } 2253 }
2437 2254
2438 void test_implementsDeferredClass() { 2255 void test_implementsDeferredClass() {
2439 resolveWithErrors(<String>[ 2256 resolveWithErrors(<String>[
2440 r''' 2257 r'''
2441 library lib1; 2258 library lib1;
2442 class A {}''', 2259 class A {}''',
(...skipping 17 matching lines...) Expand all
2460 class B {} 2277 class B {}
2461 class M {} 2278 class M {}
2462 class C = B with M implements a.A;''' 2279 class C = B with M implements a.A;'''
2463 ], <ErrorCode>[ 2280 ], <ErrorCode>[
2464 CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS 2281 CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS
2465 ]); 2282 ]);
2466 } 2283 }
2467 2284
2468 void test_implementsDisallowedClass_class_bool() { 2285 void test_implementsDisallowedClass_class_bool() {
2469 Source source = addSource("class A implements bool {}"); 2286 Source source = addSource("class A implements bool {}");
2470 computeLibrarySourceErrors(source);
2471 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2287 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2472 verify([source]); 2288 verify([source]);
2473 } 2289 }
2474 2290
2475 void test_implementsDisallowedClass_class_double() { 2291 void test_implementsDisallowedClass_class_double() {
2476 Source source = addSource("class A implements double {}"); 2292 Source source = addSource("class A implements double {}");
2477 computeLibrarySourceErrors(source);
2478 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2293 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2479 verify([source]); 2294 verify([source]);
2480 } 2295 }
2481 2296
2482 void test_implementsDisallowedClass_class_int() { 2297 void test_implementsDisallowedClass_class_int() {
2483 Source source = addSource("class A implements int {}"); 2298 Source source = addSource("class A implements int {}");
2484 computeLibrarySourceErrors(source);
2485 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2299 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2486 verify([source]); 2300 verify([source]);
2487 } 2301 }
2488 2302
2489 void test_implementsDisallowedClass_class_Null() { 2303 void test_implementsDisallowedClass_class_Null() {
2490 Source source = addSource("class A implements Null {}"); 2304 Source source = addSource("class A implements Null {}");
2491 computeLibrarySourceErrors(source);
2492 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2305 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2493 verify([source]); 2306 verify([source]);
2494 } 2307 }
2495 2308
2496 void test_implementsDisallowedClass_class_num() { 2309 void test_implementsDisallowedClass_class_num() {
2497 Source source = addSource("class A implements num {}"); 2310 Source source = addSource("class A implements num {}");
2498 computeLibrarySourceErrors(source);
2499 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2311 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2500 verify([source]); 2312 verify([source]);
2501 } 2313 }
2502 2314
2503 void test_implementsDisallowedClass_class_String() { 2315 void test_implementsDisallowedClass_class_String() {
2504 Source source = addSource("class A implements String {}"); 2316 Source source = addSource("class A implements String {}");
2505 computeLibrarySourceErrors(source);
2506 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2317 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2507 verify([source]); 2318 verify([source]);
2508 } 2319 }
2509 2320
2510 void test_implementsDisallowedClass_class_String_num() { 2321 void test_implementsDisallowedClass_class_String_num() {
2511 Source source = addSource("class A implements String, num {}"); 2322 Source source = addSource("class A implements String, num {}");
2512 computeLibrarySourceErrors(source);
2513 assertErrors(source, [ 2323 assertErrors(source, [
2514 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 2324 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS,
2515 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS 2325 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS
2516 ]); 2326 ]);
2517 verify([source]); 2327 verify([source]);
2518 } 2328 }
2519 2329
2520 void test_implementsDisallowedClass_classTypeAlias_bool() { 2330 void test_implementsDisallowedClass_classTypeAlias_bool() {
2521 Source source = addSource(r''' 2331 Source source = addSource(r'''
2522 class A {} 2332 class A {}
2523 class M {} 2333 class M {}
2524 class C = A with M implements bool;'''); 2334 class C = A with M implements bool;''');
2525 computeLibrarySourceErrors(source);
2526 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2335 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2527 verify([source]); 2336 verify([source]);
2528 } 2337 }
2529 2338
2530 void test_implementsDisallowedClass_classTypeAlias_double() { 2339 void test_implementsDisallowedClass_classTypeAlias_double() {
2531 Source source = addSource(r''' 2340 Source source = addSource(r'''
2532 class A {} 2341 class A {}
2533 class M {} 2342 class M {}
2534 class C = A with M implements double;'''); 2343 class C = A with M implements double;''');
2535 computeLibrarySourceErrors(source);
2536 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2344 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2537 verify([source]); 2345 verify([source]);
2538 } 2346 }
2539 2347
2540 void test_implementsDisallowedClass_classTypeAlias_int() { 2348 void test_implementsDisallowedClass_classTypeAlias_int() {
2541 Source source = addSource(r''' 2349 Source source = addSource(r'''
2542 class A {} 2350 class A {}
2543 class M {} 2351 class M {}
2544 class C = A with M implements int;'''); 2352 class C = A with M implements int;''');
2545 computeLibrarySourceErrors(source);
2546 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2353 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2547 verify([source]); 2354 verify([source]);
2548 } 2355 }
2549 2356
2550 void test_implementsDisallowedClass_classTypeAlias_Null() { 2357 void test_implementsDisallowedClass_classTypeAlias_Null() {
2551 Source source = addSource(r''' 2358 Source source = addSource(r'''
2552 class A {} 2359 class A {}
2553 class M {} 2360 class M {}
2554 class C = A with M implements Null;'''); 2361 class C = A with M implements Null;''');
2555 computeLibrarySourceErrors(source);
2556 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2362 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2557 verify([source]); 2363 verify([source]);
2558 } 2364 }
2559 2365
2560 void test_implementsDisallowedClass_classTypeAlias_num() { 2366 void test_implementsDisallowedClass_classTypeAlias_num() {
2561 Source source = addSource(r''' 2367 Source source = addSource(r'''
2562 class A {} 2368 class A {}
2563 class M {} 2369 class M {}
2564 class C = A with M implements num;'''); 2370 class C = A with M implements num;''');
2565 computeLibrarySourceErrors(source);
2566 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2371 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2567 verify([source]); 2372 verify([source]);
2568 } 2373 }
2569 2374
2570 void test_implementsDisallowedClass_classTypeAlias_String() { 2375 void test_implementsDisallowedClass_classTypeAlias_String() {
2571 Source source = addSource(r''' 2376 Source source = addSource(r'''
2572 class A {} 2377 class A {}
2573 class M {} 2378 class M {}
2574 class C = A with M implements String;'''); 2379 class C = A with M implements String;''');
2575 computeLibrarySourceErrors(source);
2576 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); 2380 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
2577 verify([source]); 2381 verify([source]);
2578 } 2382 }
2579 2383
2580 void test_implementsDisallowedClass_classTypeAlias_String_num() { 2384 void test_implementsDisallowedClass_classTypeAlias_String_num() {
2581 Source source = addSource(r''' 2385 Source source = addSource(r'''
2582 class A {} 2386 class A {}
2583 class M {} 2387 class M {}
2584 class C = A with M implements String, num;'''); 2388 class C = A with M implements String, num;''');
2585 computeLibrarySourceErrors(source);
2586 assertErrors(source, [ 2389 assertErrors(source, [
2587 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, 2390 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS,
2588 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS 2391 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS
2589 ]); 2392 ]);
2590 verify([source]); 2393 verify([source]);
2591 } 2394 }
2592 2395
2593 void test_implementsDynamic() { 2396 void test_implementsDynamic() {
2594 Source source = addSource("class A implements dynamic {}"); 2397 Source source = addSource("class A implements dynamic {}");
2595 computeLibrarySourceErrors(source);
2596 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]); 2398 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]);
2597 verify([source]); 2399 verify([source]);
2598 } 2400 }
2599 2401
2600 void test_implementsEnum() { 2402 void test_implementsEnum() {
2601 Source source = addSource(r''' 2403 Source source = addSource(r'''
2602 enum E { ONE } 2404 enum E { ONE }
2603 class A implements E {}'''); 2405 class A implements E {}''');
2604 computeLibrarySourceErrors(source);
2605 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_ENUM]); 2406 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_ENUM]);
2606 verify([source]); 2407 verify([source]);
2607 } 2408 }
2608 2409
2609 void test_implementsNonClass_class() { 2410 void test_implementsNonClass_class() {
2610 Source source = addSource(r''' 2411 Source source = addSource(r'''
2611 int A; 2412 int A;
2612 class B implements A {}'''); 2413 class B implements A {}''');
2613 computeLibrarySourceErrors(source);
2614 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); 2414 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]);
2615 verify([source]); 2415 verify([source]);
2616 } 2416 }
2617 2417
2618 void test_implementsNonClass_typeAlias() { 2418 void test_implementsNonClass_typeAlias() {
2619 Source source = addSource(r''' 2419 Source source = addSource(r'''
2620 class A {} 2420 class A {}
2621 class M {} 2421 class M {}
2622 int B; 2422 int B;
2623 class C = A with M implements B;'''); 2423 class C = A with M implements B;''');
2624 computeLibrarySourceErrors(source);
2625 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); 2424 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]);
2626 verify([source]); 2425 verify([source]);
2627 } 2426 }
2628 2427
2629 void test_implementsRepeated() { 2428 void test_implementsRepeated() {
2630 Source source = addSource(r''' 2429 Source source = addSource(r'''
2631 class A {} 2430 class A {}
2632 class B implements A, A {}'''); 2431 class B implements A, A {}''');
2633 computeLibrarySourceErrors(source);
2634 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_REPEATED]); 2432 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_REPEATED]);
2635 verify([source]); 2433 verify([source]);
2636 } 2434 }
2637 2435
2638 void test_implementsRepeated_3times() { 2436 void test_implementsRepeated_3times() {
2639 Source source = addSource(r''' 2437 Source source = addSource(r'''
2640 class A {} class C{} 2438 class A {} class C{}
2641 class B implements A, A, A, A {}'''); 2439 class B implements A, A, A, A {}''');
2642 computeLibrarySourceErrors(source);
2643 assertErrors(source, [ 2440 assertErrors(source, [
2644 CompileTimeErrorCode.IMPLEMENTS_REPEATED, 2441 CompileTimeErrorCode.IMPLEMENTS_REPEATED,
2645 CompileTimeErrorCode.IMPLEMENTS_REPEATED, 2442 CompileTimeErrorCode.IMPLEMENTS_REPEATED,
2646 CompileTimeErrorCode.IMPLEMENTS_REPEATED 2443 CompileTimeErrorCode.IMPLEMENTS_REPEATED
2647 ]); 2444 ]);
2648 verify([source]); 2445 verify([source]);
2649 } 2446 }
2650 2447
2651 void test_implementsSuperClass() { 2448 void test_implementsSuperClass() {
2652 Source source = addSource(r''' 2449 Source source = addSource(r'''
2653 class A {} 2450 class A {}
2654 class B extends A implements A {}'''); 2451 class B extends A implements A {}''');
2655 computeLibrarySourceErrors(source);
2656 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); 2452 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]);
2657 verify([source]); 2453 verify([source]);
2658 } 2454 }
2659 2455
2660 void test_implementsSuperClass_Object() { 2456 void test_implementsSuperClass_Object() {
2661 Source source = addSource("class A implements Object {}"); 2457 Source source = addSource("class A implements Object {}");
2662 computeLibrarySourceErrors(source);
2663 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); 2458 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]);
2664 verify([source]); 2459 verify([source]);
2665 } 2460 }
2666 2461
2667 void test_implicitThisReferenceInInitializer_field() { 2462 void test_implicitThisReferenceInInitializer_field() {
2668 Source source = addSource(r''' 2463 Source source = addSource(r'''
2669 class A { 2464 class A {
2670 var v; 2465 var v;
2671 A() : v = f; 2466 A() : v = f;
2672 var f; 2467 var f;
2673 }'''); 2468 }''');
2674 computeLibrarySourceErrors(source);
2675 assertErrors( 2469 assertErrors(
2676 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); 2470 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]);
2677 verify([source]); 2471 verify([source]);
2678 } 2472 }
2679 2473
2680 void test_implicitThisReferenceInInitializer_field2() { 2474 void test_implicitThisReferenceInInitializer_field2() {
2681 Source source = addSource(r''' 2475 Source source = addSource(r'''
2682 class A { 2476 class A {
2683 final x = 0; 2477 final x = 0;
2684 final y = x; 2478 final y = x;
2685 }'''); 2479 }''');
2686 computeLibrarySourceErrors(source);
2687 assertErrors( 2480 assertErrors(
2688 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); 2481 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]);
2689 verify([source]); 2482 verify([source]);
2690 } 2483 }
2691 2484
2692 void test_implicitThisReferenceInInitializer_invocation() { 2485 void test_implicitThisReferenceInInitializer_invocation() {
2693 Source source = addSource(r''' 2486 Source source = addSource(r'''
2694 class A { 2487 class A {
2695 var v; 2488 var v;
2696 A() : v = f(); 2489 A() : v = f();
2697 f() {} 2490 f() {}
2698 }'''); 2491 }''');
2699 computeLibrarySourceErrors(source);
2700 assertErrors( 2492 assertErrors(
2701 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); 2493 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]);
2702 verify([source]); 2494 verify([source]);
2703 } 2495 }
2704 2496
2705 void test_implicitThisReferenceInInitializer_invocationInStatic() { 2497 void test_implicitThisReferenceInInitializer_invocationInStatic() {
2706 Source source = addSource(r''' 2498 Source source = addSource(r'''
2707 class A { 2499 class A {
2708 static var F = m(); 2500 static var F = m();
2709 m() {} 2501 m() {}
2710 }'''); 2502 }''');
2711 computeLibrarySourceErrors(source);
2712 assertErrors( 2503 assertErrors(
2713 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); 2504 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]);
2714 verify([source]); 2505 verify([source]);
2715 } 2506 }
2716 2507
2717 void 2508 void
2718 test_implicitThisReferenceInInitializer_redirectingConstructorInvocation() { 2509 test_implicitThisReferenceInInitializer_redirectingConstructorInvocation() {
2719 Source source = addSource(r''' 2510 Source source = addSource(r'''
2720 class A { 2511 class A {
2721 A(p) {} 2512 A(p) {}
2722 A.named() : this(f); 2513 A.named() : this(f);
2723 var f; 2514 var f;
2724 }'''); 2515 }''');
2725 computeLibrarySourceErrors(source);
2726 assertErrors( 2516 assertErrors(
2727 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); 2517 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]);
2728 verify([source]); 2518 verify([source]);
2729 } 2519 }
2730 2520
2731 void test_implicitThisReferenceInInitializer_superConstructorInvocation() { 2521 void test_implicitThisReferenceInInitializer_superConstructorInvocation() {
2732 Source source = addSource(r''' 2522 Source source = addSource(r'''
2733 class A { 2523 class A {
2734 A(p) {} 2524 A(p) {}
2735 } 2525 }
2736 class B extends A { 2526 class B extends A {
2737 B() : super(f); 2527 B() : super(f);
2738 var f; 2528 var f;
2739 }'''); 2529 }''');
2740 computeLibrarySourceErrors(source);
2741 assertErrors( 2530 assertErrors(
2742 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); 2531 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]);
2743 verify([source]); 2532 verify([source]);
2744 } 2533 }
2745 2534
2746 void test_importInternalLibrary() { 2535 void test_importInternalLibrary() {
2747 Source source = addSource("import 'dart:_interceptors';"); 2536 Source source = addSource("import 'dart:_interceptors';");
2748 computeLibrarySourceErrors(source);
2749 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while 2537 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while
2750 // we could prevent the hint from being generated by testing the import 2538 // we could prevent the hint from being generated by testing the import
2751 // directive for the error, this is such a minor corner case that we don't 2539 // directive for the error, this is such a minor corner case that we don't
2752 // think we should add the additional computation time to figure out such 2540 // think we should add the additional computation time to figure out such
2753 // cases. 2541 // cases.
2754 assertErrors(source, 2542 assertErrors(source,
2755 [CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, HintCode.UNUSED_IMPORT]); 2543 [CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, HintCode.UNUSED_IMPORT]);
2756 verify([source]); 2544 verify([source]);
2757 } 2545 }
2758 2546
2759 void test_importInternalLibrary_js_helper() { 2547 void test_importInternalLibrary_js_helper() {
2760 Source source = addSource("import 'dart:_js_helper';"); 2548 Source source = addSource("import 'dart:_js_helper';");
2761 computeLibrarySourceErrors(source);
2762 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while 2549 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while
2763 // we could prevent the hint from being generated by testing the import 2550 // we could prevent the hint from being generated by testing the import
2764 // directive for the error, this is such a minor corner case that we don't 2551 // directive for the error, this is such a minor corner case that we don't
2765 // think we should add the additional computation time to figure out such 2552 // think we should add the additional computation time to figure out such
2766 // cases. 2553 // cases.
2767 assertErrors(source, 2554 assertErrors(source,
2768 [CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, HintCode.UNUSED_IMPORT]); 2555 [CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, HintCode.UNUSED_IMPORT]);
2769 verify([source]); 2556 verify([source]);
2770 } 2557 }
2771 2558
2772 void test_importOfNonLibrary() { 2559 void test_importOfNonLibrary() {
2773 Source source = addSource(r''' 2560 Source source = addSource(r'''
2774 library lib; 2561 library lib;
2775 import 'part.dart'; 2562 import 'part.dart';
2776 A a;'''); 2563 A a;''');
2777 addNamedSource( 2564 addNamedSource(
2778 "/part.dart", 2565 "/part.dart",
2779 r''' 2566 r'''
2780 part of lib; 2567 part of lib;
2781 class A{}'''); 2568 class A{}''');
2782 computeLibrarySourceErrors(source);
2783 assertErrors(source, [CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); 2569 assertErrors(source, [CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]);
2784 verify([source]); 2570 verify([source]);
2785 } 2571 }
2786 2572
2787 void test_inconsistentCaseExpressionTypes() { 2573 void test_inconsistentCaseExpressionTypes() {
2788 Source source = addSource(r''' 2574 Source source = addSource(r'''
2789 f(var p) { 2575 f(var p) {
2790 switch (p) { 2576 switch (p) {
2791 case 1: 2577 case 1:
2792 break; 2578 break;
2793 case 'a': 2579 case 'a':
2794 break; 2580 break;
2795 } 2581 }
2796 }'''); 2582 }''');
2797 computeLibrarySourceErrors(source);
2798 assertErrors( 2583 assertErrors(
2799 source, [CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]); 2584 source, [CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]);
2800 verify([source]); 2585 verify([source]);
2801 } 2586 }
2802 2587
2803 void test_inconsistentCaseExpressionTypes_dynamic() { 2588 void test_inconsistentCaseExpressionTypes_dynamic() {
2804 // Even though A.S and S have a static type of "dynamic", we should see 2589 // Even though A.S and S have a static type of "dynamic", we should see
2805 // that they fail to match 3, because they are constant strings. 2590 // that they fail to match 3, because they are constant strings.
2806 Source source = addSource(r''' 2591 Source source = addSource(r'''
2807 class A { 2592 class A {
2808 static const S = 'A.S'; 2593 static const S = 'A.S';
2809 } 2594 }
2810 2595
2811 const S = 'S'; 2596 const S = 'S';
2812 2597
2813 foo(var p) { 2598 foo(var p) {
2814 switch (p) { 2599 switch (p) {
2815 case 3: 2600 case 3:
2816 break; 2601 break;
2817 case S: 2602 case S:
2818 break; 2603 break;
2819 case A.S: 2604 case A.S:
2820 break; 2605 break;
2821 } 2606 }
2822 }'''); 2607 }''');
2823 computeLibrarySourceErrors(source);
2824 assertErrors(source, [ 2608 assertErrors(source, [
2825 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, 2609 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES,
2826 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES 2610 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES
2827 ]); 2611 ]);
2828 verify([source]); 2612 verify([source]);
2829 } 2613 }
2830 2614
2831 void test_inconsistentCaseExpressionTypes_repeated() { 2615 void test_inconsistentCaseExpressionTypes_repeated() {
2832 Source source = addSource(r''' 2616 Source source = addSource(r'''
2833 f(var p) { 2617 f(var p) {
2834 switch (p) { 2618 switch (p) {
2835 case 1: 2619 case 1:
2836 break; 2620 break;
2837 case 'a': 2621 case 'a':
2838 break; 2622 break;
2839 case 'b': 2623 case 'b':
2840 break; 2624 break;
2841 } 2625 }
2842 }'''); 2626 }''');
2843 computeLibrarySourceErrors(source);
2844 assertErrors(source, [ 2627 assertErrors(source, [
2845 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, 2628 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES,
2846 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES 2629 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES
2847 ]); 2630 ]);
2848 verify([source]); 2631 verify([source]);
2849 } 2632 }
2850 2633
2851 void test_initializerForNonExistent_const() { 2634 void test_initializerForNonExistent_const() {
2852 // Check that the absence of a matching field doesn't cause a 2635 // Check that the absence of a matching field doesn't cause a
2853 // crash during constant evaluation. 2636 // crash during constant evaluation.
2854 Source source = addSource(r''' 2637 Source source = addSource(r'''
2855 class A { 2638 class A {
2856 const A() : x = 'foo'; 2639 const A() : x = 'foo';
2857 } 2640 }
2858 A a = const A();'''); 2641 A a = const A();''');
2859 computeLibrarySourceErrors(source);
2860 assertErrors( 2642 assertErrors(
2861 source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD]); 2643 source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD]);
2862 } 2644 }
2863 2645
2864 void test_initializerForNonExistent_initializer() { 2646 void test_initializerForNonExistent_initializer() {
2865 Source source = addSource(r''' 2647 Source source = addSource(r'''
2866 class A { 2648 class A {
2867 A() : x = 0 {} 2649 A() : x = 0 {}
2868 }'''); 2650 }''');
2869 computeLibrarySourceErrors(source);
2870 assertErrors( 2651 assertErrors(
2871 source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD]); 2652 source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD]);
2872 } 2653 }
2873 2654
2874 void test_initializerForStaticField() { 2655 void test_initializerForStaticField() {
2875 Source source = addSource(r''' 2656 Source source = addSource(r'''
2876 class A { 2657 class A {
2877 static int x; 2658 static int x;
2878 A() : x = 0 {} 2659 A() : x = 0 {}
2879 }'''); 2660 }''');
2880 computeLibrarySourceErrors(source);
2881 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD]); 2661 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD]);
2882 verify([source]); 2662 verify([source]);
2883 } 2663 }
2884 2664
2885 void test_initializingFormalForNonExistentField() { 2665 void test_initializingFormalForNonExistentField() {
2886 Source source = addSource(r''' 2666 Source source = addSource(r'''
2887 class A { 2667 class A {
2888 A(this.x) {} 2668 A(this.x) {}
2889 }'''); 2669 }''');
2890 computeLibrarySourceErrors(source);
2891 assertErrors(source, 2670 assertErrors(source,
2892 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); 2671 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]);
2893 verify([source]); 2672 verify([source]);
2894 } 2673 }
2895 2674
2896 void test_initializingFormalForNonExistentField_notInEnclosingClass() { 2675 void test_initializingFormalForNonExistentField_notInEnclosingClass() {
2897 Source source = addSource(r''' 2676 Source source = addSource(r'''
2898 class A { 2677 class A {
2899 int x; 2678 int x;
2900 } 2679 }
2901 class B extends A { 2680 class B extends A {
2902 B(this.x) {} 2681 B(this.x) {}
2903 }'''); 2682 }''');
2904 computeLibrarySourceErrors(source);
2905 assertErrors(source, 2683 assertErrors(source,
2906 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); 2684 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]);
2907 verify([source]); 2685 verify([source]);
2908 } 2686 }
2909 2687
2910 void test_initializingFormalForNonExistentField_optional() { 2688 void test_initializingFormalForNonExistentField_optional() {
2911 Source source = addSource(r''' 2689 Source source = addSource(r'''
2912 class A { 2690 class A {
2913 A([this.x]) {} 2691 A([this.x]) {}
2914 }'''); 2692 }''');
2915 computeLibrarySourceErrors(source);
2916 assertErrors(source, 2693 assertErrors(source,
2917 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); 2694 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]);
2918 verify([source]); 2695 verify([source]);
2919 } 2696 }
2920 2697
2921 void test_initializingFormalForNonExistentField_synthetic() { 2698 void test_initializingFormalForNonExistentField_synthetic() {
2922 Source source = addSource(r''' 2699 Source source = addSource(r'''
2923 class A { 2700 class A {
2924 int get x => 1; 2701 int get x => 1;
2925 A(this.x) {} 2702 A(this.x) {}
2926 }'''); 2703 }''');
2927 computeLibrarySourceErrors(source);
2928 assertErrors(source, 2704 assertErrors(source,
2929 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); 2705 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]);
2930 verify([source]); 2706 verify([source]);
2931 } 2707 }
2932 2708
2933 void test_initializingFormalForStaticField() { 2709 void test_initializingFormalForStaticField() {
2934 Source source = addSource(r''' 2710 Source source = addSource(r'''
2935 class A { 2711 class A {
2936 static int x; 2712 static int x;
2937 A([this.x]) {} 2713 A([this.x]) {}
2938 }'''); 2714 }''');
2939 computeLibrarySourceErrors(source);
2940 assertErrors( 2715 assertErrors(
2941 source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD]); 2716 source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD]);
2942 verify([source]); 2717 verify([source]);
2943 } 2718 }
2944 2719
2945 void test_instanceMemberAccessFromFactory_named() { 2720 void test_instanceMemberAccessFromFactory_named() {
2946 Source source = addSource(r''' 2721 Source source = addSource(r'''
2947 class A { 2722 class A {
2948 m() {} 2723 m() {}
2949 A(); 2724 A();
2950 factory A.make() { 2725 factory A.make() {
2951 m(); 2726 m();
2952 return new A(); 2727 return new A();
2953 } 2728 }
2954 }'''); 2729 }''');
2955 computeLibrarySourceErrors(source);
2956 assertErrors( 2730 assertErrors(
2957 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY]); 2731 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY]);
2958 verify([source]); 2732 verify([source]);
2959 } 2733 }
2960 2734
2961 void test_instanceMemberAccessFromFactory_unnamed() { 2735 void test_instanceMemberAccessFromFactory_unnamed() {
2962 Source source = addSource(r''' 2736 Source source = addSource(r'''
2963 class A { 2737 class A {
2964 m() {} 2738 m() {}
2965 A._(); 2739 A._();
2966 factory A() { 2740 factory A() {
2967 m(); 2741 m();
2968 return new A._(); 2742 return new A._();
2969 } 2743 }
2970 }'''); 2744 }''');
2971 computeLibrarySourceErrors(source);
2972 assertErrors( 2745 assertErrors(
2973 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY]); 2746 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY]);
2974 verify([source]); 2747 verify([source]);
2975 } 2748 }
2976 2749
2977 void test_instanceMemberAccessFromStatic_field() { 2750 void test_instanceMemberAccessFromStatic_field() {
2978 Source source = addSource(r''' 2751 Source source = addSource(r'''
2979 class A { 2752 class A {
2980 int f; 2753 int f;
2981 static foo() { 2754 static foo() {
2982 f; 2755 f;
2983 } 2756 }
2984 }'''); 2757 }''');
2985 computeLibrarySourceErrors(source);
2986 assertErrors( 2758 assertErrors(
2987 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); 2759 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]);
2988 verify([source]); 2760 verify([source]);
2989 } 2761 }
2990 2762
2991 void test_instanceMemberAccessFromStatic_getter() { 2763 void test_instanceMemberAccessFromStatic_getter() {
2992 Source source = addSource(r''' 2764 Source source = addSource(r'''
2993 class A { 2765 class A {
2994 get g => null; 2766 get g => null;
2995 static foo() { 2767 static foo() {
2996 g; 2768 g;
2997 } 2769 }
2998 }'''); 2770 }''');
2999 computeLibrarySourceErrors(source);
3000 assertErrors( 2771 assertErrors(
3001 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); 2772 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]);
3002 verify([source]); 2773 verify([source]);
3003 } 2774 }
3004 2775
3005 void test_instanceMemberAccessFromStatic_method() { 2776 void test_instanceMemberAccessFromStatic_method() {
3006 Source source = addSource(r''' 2777 Source source = addSource(r'''
3007 class A { 2778 class A {
3008 m() {} 2779 m() {}
3009 static foo() { 2780 static foo() {
3010 m(); 2781 m();
3011 } 2782 }
3012 }'''); 2783 }''');
3013 computeLibrarySourceErrors(source);
3014 assertErrors( 2784 assertErrors(
3015 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); 2785 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]);
3016 verify([source]); 2786 verify([source]);
3017 } 2787 }
3018 2788
3019 void test_instantiateEnum_const() { 2789 void test_instantiateEnum_const() {
3020 Source source = addSource(r''' 2790 Source source = addSource(r'''
3021 enum E { ONE } 2791 enum E { ONE }
3022 E e(String name) { 2792 E e(String name) {
3023 return const E(); 2793 return const E();
3024 }'''); 2794 }''');
3025 computeLibrarySourceErrors(source);
3026 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); 2795 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]);
3027 verify([source]); 2796 verify([source]);
3028 } 2797 }
3029 2798
3030 void test_instantiateEnum_new() { 2799 void test_instantiateEnum_new() {
3031 Source source = addSource(r''' 2800 Source source = addSource(r'''
3032 enum E { ONE } 2801 enum E { ONE }
3033 E e(String name) { 2802 E e(String name) {
3034 return new E(); 2803 return new E();
3035 }'''); 2804 }''');
3036 computeLibrarySourceErrors(source);
3037 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); 2805 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]);
3038 verify([source]); 2806 verify([source]);
3039 } 2807 }
3040 2808
3041 void test_invalidAnnotation_getter() { 2809 void test_invalidAnnotation_getter() {
3042 Source source = addSource(r''' 2810 Source source = addSource(r'''
3043 get V => 0; 2811 get V => 0;
3044 @V 2812 @V
3045 main() { 2813 main() {
3046 }'''); 2814 }''');
3047 computeLibrarySourceErrors(source);
3048 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2815 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3049 verify([source]); 2816 verify([source]);
3050 } 2817 }
3051 2818
3052 void test_invalidAnnotation_importWithPrefix_getter() { 2819 void test_invalidAnnotation_importWithPrefix_getter() {
3053 addNamedSource( 2820 addNamedSource(
3054 "/lib.dart", 2821 "/lib.dart",
3055 r''' 2822 r'''
3056 library lib; 2823 library lib;
3057 get V => 0;'''); 2824 get V => 0;''');
3058 Source source = addSource(r''' 2825 Source source = addSource(r'''
3059 import 'lib.dart' as p; 2826 import 'lib.dart' as p;
3060 @p.V 2827 @p.V
3061 main() { 2828 main() {
3062 }'''); 2829 }''');
3063 computeLibrarySourceErrors(source);
3064 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2830 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3065 verify([source]); 2831 verify([source]);
3066 } 2832 }
3067 2833
3068 void test_invalidAnnotation_importWithPrefix_notConstantVariable() { 2834 void test_invalidAnnotation_importWithPrefix_notConstantVariable() {
3069 addNamedSource( 2835 addNamedSource(
3070 "/lib.dart", 2836 "/lib.dart",
3071 r''' 2837 r'''
3072 library lib; 2838 library lib;
3073 final V = 0;'''); 2839 final V = 0;''');
3074 Source source = addSource(r''' 2840 Source source = addSource(r'''
3075 import 'lib.dart' as p; 2841 import 'lib.dart' as p;
3076 @p.V 2842 @p.V
3077 main() { 2843 main() {
3078 }'''); 2844 }''');
3079 computeLibrarySourceErrors(source);
3080 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2845 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3081 verify([source]); 2846 verify([source]);
3082 } 2847 }
3083 2848
3084 void 2849 void
3085 test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocation () { 2850 test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocation () {
3086 addNamedSource( 2851 addNamedSource(
3087 "/lib.dart", 2852 "/lib.dart",
3088 r''' 2853 r'''
3089 library lib; 2854 library lib;
3090 typedef V();'''); 2855 typedef V();''');
3091 Source source = addSource(r''' 2856 Source source = addSource(r'''
3092 import 'lib.dart' as p; 2857 import 'lib.dart' as p;
3093 @p.V 2858 @p.V
3094 main() { 2859 main() {
3095 }'''); 2860 }''');
3096 computeLibrarySourceErrors(source);
3097 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2861 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3098 verify([source]); 2862 verify([source]);
3099 } 2863 }
3100 2864
3101 void test_invalidAnnotation_notConstantVariable() { 2865 void test_invalidAnnotation_notConstantVariable() {
3102 Source source = addSource(r''' 2866 Source source = addSource(r'''
3103 final V = 0; 2867 final V = 0;
3104 @V 2868 @V
3105 main() { 2869 main() {
3106 }'''); 2870 }''');
3107 computeLibrarySourceErrors(source);
3108 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2871 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3109 verify([source]); 2872 verify([source]);
3110 } 2873 }
3111 2874
3112 void test_invalidAnnotation_notVariableOrConstructorInvocation() { 2875 void test_invalidAnnotation_notVariableOrConstructorInvocation() {
3113 Source source = addSource(r''' 2876 Source source = addSource(r'''
3114 typedef V(); 2877 typedef V();
3115 @V 2878 @V
3116 main() { 2879 main() {
3117 }'''); 2880 }''');
3118 computeLibrarySourceErrors(source);
3119 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2881 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3120 verify([source]); 2882 verify([source]);
3121 } 2883 }
3122 2884
3123 void test_invalidAnnotation_staticMethodReference() { 2885 void test_invalidAnnotation_staticMethodReference() {
3124 Source source = addSource(r''' 2886 Source source = addSource(r'''
3125 class A { 2887 class A {
3126 static f() {} 2888 static f() {}
3127 } 2889 }
3128 @A.f 2890 @A.f
3129 main() { 2891 main() {
3130 }'''); 2892 }''');
3131 computeLibrarySourceErrors(source);
3132 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2893 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3133 verify([source]); 2894 verify([source]);
3134 } 2895 }
3135 2896
3136 void test_invalidAnnotation_unresolved_identifier() { 2897 void test_invalidAnnotation_unresolved_identifier() {
3137 Source source = addSource(r''' 2898 Source source = addSource(r'''
3138 @unresolved 2899 @unresolved
3139 main() { 2900 main() {
3140 }'''); 2901 }''');
3141 computeLibrarySourceErrors(source);
3142 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2902 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3143 } 2903 }
3144 2904
3145 void test_invalidAnnotation_unresolved_invocation() { 2905 void test_invalidAnnotation_unresolved_invocation() {
3146 Source source = addSource(r''' 2906 Source source = addSource(r'''
3147 @Unresolved() 2907 @Unresolved()
3148 main() { 2908 main() {
3149 }'''); 2909 }''');
3150 computeLibrarySourceErrors(source);
3151 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2910 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3152 } 2911 }
3153 2912
3154 void test_invalidAnnotation_unresolved_prefixedIdentifier() { 2913 void test_invalidAnnotation_unresolved_prefixedIdentifier() {
3155 Source source = addSource(r''' 2914 Source source = addSource(r'''
3156 import 'dart:math' as p; 2915 import 'dart:math' as p;
3157 @p.unresolved 2916 @p.unresolved
3158 main() { 2917 main() {
3159 }'''); 2918 }''');
3160 computeLibrarySourceErrors(source);
3161 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2919 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3162 } 2920 }
3163 2921
3164 void test_invalidAnnotation_useLibraryScope() { 2922 void test_invalidAnnotation_useLibraryScope() {
3165 Source source = addSource(r''' 2923 Source source = addSource(r'''
3166 @foo 2924 @foo
3167 class A { 2925 class A {
3168 static const foo = null; 2926 static const foo = null;
3169 }'''); 2927 }''');
3170 computeLibrarySourceErrors(source);
3171 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 2928 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
3172 } 2929 }
3173 2930
3174 void test_invalidAnnotationFromDeferredLibrary() { 2931 void test_invalidAnnotationFromDeferredLibrary() {
3175 // See test_invalidAnnotation_notConstantVariable 2932 // See test_invalidAnnotation_notConstantVariable
3176 resolveWithErrors(<String>[ 2933 resolveWithErrors(<String>[
3177 r''' 2934 r'''
3178 library lib1; 2935 library lib1;
3179 class V { const V(); } 2936 class V { const V(); }
3180 const v = const V();''', 2937 const v = const V();''',
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3216 CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY 2973 CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY
3217 ]); 2974 ]);
3218 } 2975 }
3219 2976
3220 void test_invalidConstructorName_notEnclosingClassName_defined() { 2977 void test_invalidConstructorName_notEnclosingClassName_defined() {
3221 Source source = addSource(r''' 2978 Source source = addSource(r'''
3222 class A { 2979 class A {
3223 B() : super(); 2980 B() : super();
3224 } 2981 }
3225 class B {}'''); 2982 class B {}''');
3226 computeLibrarySourceErrors(source);
3227 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); 2983 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]);
3228 // no verify() call, "B" is not resolved 2984 // no verify() call, "B" is not resolved
3229 } 2985 }
3230 2986
3231 void test_invalidConstructorName_notEnclosingClassName_undefined() { 2987 void test_invalidConstructorName_notEnclosingClassName_undefined() {
3232 Source source = addSource(r''' 2988 Source source = addSource(r'''
3233 class A { 2989 class A {
3234 B() : super(); 2990 B() : super();
3235 }'''); 2991 }''');
3236 computeLibrarySourceErrors(source);
3237 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); 2992 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]);
3238 // no verify() call, "B" is not resolved 2993 // no verify() call, "B" is not resolved
3239 } 2994 }
3240 2995
3241 void test_invalidFactoryNameNotAClass_notClassName() { 2996 void test_invalidFactoryNameNotAClass_notClassName() {
3242 Source source = addSource(r''' 2997 Source source = addSource(r'''
3243 int B; 2998 int B;
3244 class A { 2999 class A {
3245 factory B() => null; 3000 factory B() => null;
3246 }'''); 3001 }''');
3247 computeLibrarySourceErrors(source);
3248 assertErrors( 3002 assertErrors(
3249 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); 3003 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]);
3250 verify([source]); 3004 verify([source]);
3251 } 3005 }
3252 3006
3253 void test_invalidFactoryNameNotAClass_notEnclosingClassName() { 3007 void test_invalidFactoryNameNotAClass_notEnclosingClassName() {
3254 Source source = addSource(r''' 3008 Source source = addSource(r'''
3255 class A { 3009 class A {
3256 factory B() => null; 3010 factory B() => null;
3257 }'''); 3011 }''');
3258 computeLibrarySourceErrors(source);
3259 assertErrors( 3012 assertErrors(
3260 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); 3013 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]);
3261 // no verify() call, "B" is not resolved 3014 // no verify() call, "B" is not resolved
3262 } 3015 }
3263 3016
3264 void test_invalidModifierOnConstructor_async() { 3017 void test_invalidModifierOnConstructor_async() {
3265 Source source = addSource(r''' 3018 Source source = addSource(r'''
3266 class A { 3019 class A {
3267 A() async {} 3020 A() async {}
3268 }'''); 3021 }''');
3269 computeLibrarySourceErrors(source);
3270 assertErrors( 3022 assertErrors(
3271 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); 3023 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]);
3272 verify([source]); 3024 verify([source]);
3273 } 3025 }
3274 3026
3275 void test_invalidModifierOnConstructor_asyncStar() { 3027 void test_invalidModifierOnConstructor_asyncStar() {
3276 Source source = addSource(r''' 3028 Source source = addSource(r'''
3277 class A { 3029 class A {
3278 A() async* {} 3030 A() async* {}
3279 }'''); 3031 }''');
3280 computeLibrarySourceErrors(source);
3281 assertErrors( 3032 assertErrors(
3282 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); 3033 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]);
3283 verify([source]); 3034 verify([source]);
3284 } 3035 }
3285 3036
3286 void test_invalidModifierOnConstructor_syncStar() { 3037 void test_invalidModifierOnConstructor_syncStar() {
3287 Source source = addSource(r''' 3038 Source source = addSource(r'''
3288 class A { 3039 class A {
3289 A() sync* {} 3040 A() sync* {}
3290 }'''); 3041 }''');
3291 computeLibrarySourceErrors(source);
3292 assertErrors( 3042 assertErrors(
3293 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); 3043 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]);
3294 verify([source]); 3044 verify([source]);
3295 } 3045 }
3296 3046
3297 void test_invalidModifierOnSetter_member_async() { 3047 void test_invalidModifierOnSetter_member_async() {
3298 Source source = addSource(r''' 3048 Source source = addSource(r'''
3299 class A { 3049 class A {
3300 set x(v) async {} 3050 set x(v) async {}
3301 }'''); 3051 }''');
3302 computeLibrarySourceErrors(source);
3303 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 3052 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
3304 verify([source]); 3053 verify([source]);
3305 } 3054 }
3306 3055
3307 void test_invalidModifierOnSetter_member_asyncStar() { 3056 void test_invalidModifierOnSetter_member_asyncStar() {
3308 Source source = addSource(r''' 3057 Source source = addSource(r'''
3309 class A { 3058 class A {
3310 set x(v) async* {} 3059 set x(v) async* {}
3311 }'''); 3060 }''');
3312 computeLibrarySourceErrors(source);
3313 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 3061 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
3314 verify([source]); 3062 verify([source]);
3315 } 3063 }
3316 3064
3317 void test_invalidModifierOnSetter_member_syncStar() { 3065 void test_invalidModifierOnSetter_member_syncStar() {
3318 Source source = addSource(r''' 3066 Source source = addSource(r'''
3319 class A { 3067 class A {
3320 set x(v) sync* {} 3068 set x(v) sync* {}
3321 }'''); 3069 }''');
3322 computeLibrarySourceErrors(source);
3323 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 3070 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
3324 verify([source]); 3071 verify([source]);
3325 } 3072 }
3326 3073
3327 void test_invalidModifierOnSetter_topLevel_async() { 3074 void test_invalidModifierOnSetter_topLevel_async() {
3328 Source source = addSource("set x(v) async {}"); 3075 Source source = addSource("set x(v) async {}");
3329 computeLibrarySourceErrors(source);
3330 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 3076 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
3331 verify([source]); 3077 verify([source]);
3332 } 3078 }
3333 3079
3334 void test_invalidModifierOnSetter_topLevel_asyncStar() { 3080 void test_invalidModifierOnSetter_topLevel_asyncStar() {
3335 Source source = addSource("set x(v) async* {}"); 3081 Source source = addSource("set x(v) async* {}");
3336 computeLibrarySourceErrors(source);
3337 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 3082 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
3338 verify([source]); 3083 verify([source]);
3339 } 3084 }
3340 3085
3341 void test_invalidModifierOnSetter_topLevel_syncStar() { 3086 void test_invalidModifierOnSetter_topLevel_syncStar() {
3342 Source source = addSource("set x(v) sync* {}"); 3087 Source source = addSource("set x(v) sync* {}");
3343 computeLibrarySourceErrors(source);
3344 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 3088 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
3345 verify([source]); 3089 verify([source]);
3346 } 3090 }
3347 3091
3348 void test_invalidReferenceToThis_factoryConstructor() { 3092 void test_invalidReferenceToThis_factoryConstructor() {
3349 Source source = addSource(r''' 3093 Source source = addSource(r'''
3350 class A { 3094 class A {
3351 factory A() { return this; } 3095 factory A() { return this; }
3352 }'''); 3096 }''');
3353 computeLibrarySourceErrors(source);
3354 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 3097 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
3355 verify([source]); 3098 verify([source]);
3356 } 3099 }
3357 3100
3358 void test_invalidReferenceToThis_instanceVariableInitializer_inConstructor() { 3101 void test_invalidReferenceToThis_instanceVariableInitializer_inConstructor() {
3359 Source source = addSource(r''' 3102 Source source = addSource(r'''
3360 class A { 3103 class A {
3361 var f; 3104 var f;
3362 A() : f = this; 3105 A() : f = this;
3363 }'''); 3106 }''');
3364 computeLibrarySourceErrors(source);
3365 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 3107 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
3366 verify([source]); 3108 verify([source]);
3367 } 3109 }
3368 3110
3369 void test_invalidReferenceToThis_instanceVariableInitializer_inDeclaration() { 3111 void test_invalidReferenceToThis_instanceVariableInitializer_inDeclaration() {
3370 Source source = addSource(r''' 3112 Source source = addSource(r'''
3371 class A { 3113 class A {
3372 var f = this; 3114 var f = this;
3373 }'''); 3115 }''');
3374 computeLibrarySourceErrors(source);
3375 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 3116 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
3376 verify([source]); 3117 verify([source]);
3377 } 3118 }
3378 3119
3379 void test_invalidReferenceToThis_staticMethod() { 3120 void test_invalidReferenceToThis_staticMethod() {
3380 Source source = addSource(r''' 3121 Source source = addSource(r'''
3381 class A { 3122 class A {
3382 static m() { return this; } 3123 static m() { return this; }
3383 }'''); 3124 }''');
3384 computeLibrarySourceErrors(source);
3385 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 3125 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
3386 verify([source]); 3126 verify([source]);
3387 } 3127 }
3388 3128
3389 void test_invalidReferenceToThis_staticVariableInitializer() { 3129 void test_invalidReferenceToThis_staticVariableInitializer() {
3390 Source source = addSource(r''' 3130 Source source = addSource(r'''
3391 class A { 3131 class A {
3392 static A f = this; 3132 static A f = this;
3393 }'''); 3133 }''');
3394 computeLibrarySourceErrors(source);
3395 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 3134 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
3396 verify([source]); 3135 verify([source]);
3397 } 3136 }
3398 3137
3399 void test_invalidReferenceToThis_superInitializer() { 3138 void test_invalidReferenceToThis_superInitializer() {
3400 Source source = addSource(r''' 3139 Source source = addSource(r'''
3401 class A { 3140 class A {
3402 A(var x) {} 3141 A(var x) {}
3403 } 3142 }
3404 class B extends A { 3143 class B extends A {
3405 B() : super(this); 3144 B() : super(this);
3406 }'''); 3145 }''');
3407 computeLibrarySourceErrors(source);
3408 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 3146 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
3409 verify([source]); 3147 verify([source]);
3410 } 3148 }
3411 3149
3412 void test_invalidReferenceToThis_topLevelFunction() { 3150 void test_invalidReferenceToThis_topLevelFunction() {
3413 Source source = addSource("f() { return this; }"); 3151 Source source = addSource("f() { return this; }");
3414 computeLibrarySourceErrors(source);
3415 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 3152 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
3416 verify([source]); 3153 verify([source]);
3417 } 3154 }
3418 3155
3419 void test_invalidReferenceToThis_variableInitializer() { 3156 void test_invalidReferenceToThis_variableInitializer() {
3420 Source source = addSource("int x = this;"); 3157 Source source = addSource("int x = this;");
3421 computeLibrarySourceErrors(source);
3422 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); 3158 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
3423 verify([source]); 3159 verify([source]);
3424 } 3160 }
3425 3161
3426 void test_invalidTypeArgumentInConstList() { 3162 void test_invalidTypeArgumentInConstList() {
3427 Source source = addSource(r''' 3163 Source source = addSource(r'''
3428 class A<E> { 3164 class A<E> {
3429 m() { 3165 m() {
3430 return const <E>[]; 3166 return const <E>[];
3431 } 3167 }
3432 }'''); 3168 }''');
3433 computeLibrarySourceErrors(source);
3434 assertErrors( 3169 assertErrors(
3435 source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST]); 3170 source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST]);
3436 verify([source]); 3171 verify([source]);
3437 } 3172 }
3438 3173
3439 void test_invalidTypeArgumentInConstMap() { 3174 void test_invalidTypeArgumentInConstMap() {
3440 Source source = addSource(r''' 3175 Source source = addSource(r'''
3441 class A<E> { 3176 class A<E> {
3442 m() { 3177 m() {
3443 return const <String, E>{}; 3178 return const <String, E>{};
3444 } 3179 }
3445 }'''); 3180 }''');
3446 computeLibrarySourceErrors(source);
3447 assertErrors( 3181 assertErrors(
3448 source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]); 3182 source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]);
3449 verify([source]); 3183 verify([source]);
3450 } 3184 }
3451 3185
3452 void test_invalidUri_export() { 3186 void test_invalidUri_export() {
3453 Source source = addSource("export 'ht:';"); 3187 Source source = addSource("export 'ht:';");
3454 computeLibrarySourceErrors(source);
3455 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); 3188 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]);
3456 } 3189 }
3457 3190
3458 void test_invalidUri_import() { 3191 void test_invalidUri_import() {
3459 Source source = addSource("import 'ht:';"); 3192 Source source = addSource("import 'ht:';");
3460 computeLibrarySourceErrors(source);
3461 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); 3193 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]);
3462 } 3194 }
3463 3195
3464 void test_invalidUri_part() { 3196 void test_invalidUri_part() {
3465 Source source = addSource(r''' 3197 Source source = addSource(r'''
3466 library lib; 3198 library lib;
3467 part 'ht:';'''); 3199 part 'ht:';''');
3468 computeLibrarySourceErrors(source);
3469 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); 3200 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]);
3470 } 3201 }
3471 3202
3472 void test_isInConstInstanceCreation_restored() { 3203 void test_isInConstInstanceCreation_restored() {
3473 // If ErrorVerifier._isInConstInstanceCreation is not properly restored on 3204 // If ErrorVerifier._isInConstInstanceCreation is not properly restored on
3474 // exit from visitInstanceCreationExpression, the error at (1) will be 3205 // exit from visitInstanceCreationExpression, the error at (1) will be
3475 // treated as a warning rather than an error. 3206 // treated as a warning rather than an error.
3476 Source source = addSource(r''' 3207 Source source = addSource(r'''
3477 class Foo<T extends num> { 3208 class Foo<T extends num> {
3478 const Foo(x, y); 3209 const Foo(x, y);
3479 } 3210 }
3480 const x = const Foo<int>(const Foo<int>(0, 1), 3211 const x = const Foo<int>(const Foo<int>(0, 1),
3481 const <Foo<String>>[]); // (1) 3212 const <Foo<String>>[]); // (1)
3482 '''); 3213 ''');
3483 computeLibrarySourceErrors(source);
3484 assertErrors( 3214 assertErrors(
3485 source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); 3215 source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
3486 verify([source]); 3216 verify([source]);
3487 } 3217 }
3488 3218
3489 void test_isInInstanceVariableInitializer_restored() { 3219 void test_isInInstanceVariableInitializer_restored() {
3490 // If ErrorVerifier._isInInstanceVariableInitializer is not properly 3220 // If ErrorVerifier._isInInstanceVariableInitializer is not properly
3491 // restored on exit from visitVariableDeclaration, the error at (1) 3221 // restored on exit from visitVariableDeclaration, the error at (1)
3492 // won't be detected. 3222 // won't be detected.
3493 Source source = addSource(r''' 3223 Source source = addSource(r'''
3494 class Foo { 3224 class Foo {
3495 var bar; 3225 var bar;
3496 Map foo = { 3226 Map foo = {
3497 'bar': () { 3227 'bar': () {
3498 var _bar; 3228 var _bar;
3499 }, 3229 },
3500 'bop': _foo // (1) 3230 'bop': _foo // (1)
3501 }; 3231 };
3502 _foo() { 3232 _foo() {
3503 } 3233 }
3504 }'''); 3234 }''');
3505 computeLibrarySourceErrors(source);
3506 assertErrors( 3235 assertErrors(
3507 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); 3236 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]);
3508 verify([source]); 3237 verify([source]);
3509 } 3238 }
3510 3239
3511 void test_labelInOuterScope() { 3240 void test_labelInOuterScope() {
3512 Source source = addSource(r''' 3241 Source source = addSource(r'''
3513 class A { 3242 class A {
3514 void m(int i) { 3243 void m(int i) {
3515 l: while (i > 0) { 3244 l: while (i > 0) {
3516 void f() { 3245 void f() {
3517 break l; 3246 break l;
3518 }; 3247 };
3519 } 3248 }
3520 } 3249 }
3521 }'''); 3250 }''');
3522 computeLibrarySourceErrors(source);
3523 assertErrors(source, [CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE]); 3251 assertErrors(source, [CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE]);
3524 // We cannot verify resolution with unresolvable labels 3252 // We cannot verify resolution with unresolvable labels
3525 } 3253 }
3526 3254
3527 void test_labelUndefined_break() { 3255 void test_labelUndefined_break() {
3528 Source source = addSource(r''' 3256 Source source = addSource(r'''
3529 f() { 3257 f() {
3530 x: while (true) { 3258 x: while (true) {
3531 break y; 3259 break y;
3532 } 3260 }
3533 }'''); 3261 }''');
3534 computeLibrarySourceErrors(source);
3535 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); 3262 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]);
3536 // We cannot verify resolution with undefined labels 3263 // We cannot verify resolution with undefined labels
3537 } 3264 }
3538 3265
3539 void test_labelUndefined_continue() { 3266 void test_labelUndefined_continue() {
3540 Source source = addSource(r''' 3267 Source source = addSource(r'''
3541 f() { 3268 f() {
3542 x: while (true) { 3269 x: while (true) {
3543 continue y; 3270 continue y;
3544 } 3271 }
3545 }'''); 3272 }''');
3546 computeLibrarySourceErrors(source);
3547 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); 3273 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]);
3548 // We cannot verify resolution with undefined labels 3274 // We cannot verify resolution with undefined labels
3549 } 3275 }
3550 3276
3551 void test_length_of_erroneous_constant() { 3277 void test_length_of_erroneous_constant() {
3552 // Attempting to compute the length of constant that couldn't be evaluated 3278 // Attempting to compute the length of constant that couldn't be evaluated
3553 // (due to an error) should not crash the analyzer (see dartbug.com/23383) 3279 // (due to an error) should not crash the analyzer (see dartbug.com/23383)
3554 Source source = addSource("const int i = (1 ? 'alpha' : 'beta').length;"); 3280 Source source = addSource("const int i = (1 ? 'alpha' : 'beta').length;");
3555 computeLibrarySourceErrors(source);
3556 assertErrors(source, [ 3281 assertErrors(source, [
3557 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE, 3282 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE,
3558 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 3283 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
3559 StaticTypeWarningCode.NON_BOOL_CONDITION 3284 StaticTypeWarningCode.NON_BOOL_CONDITION
3560 ]); 3285 ]);
3561 verify([source]); 3286 verify([source]);
3562 } 3287 }
3563 3288
3564 void test_memberWithClassName_field() { 3289 void test_memberWithClassName_field() {
3565 Source source = addSource(r''' 3290 Source source = addSource(r'''
3566 class A { 3291 class A {
3567 int A = 0; 3292 int A = 0;
3568 }'''); 3293 }''');
3569 computeLibrarySourceErrors(source);
3570 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); 3294 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]);
3571 verify([source]); 3295 verify([source]);
3572 } 3296 }
3573 3297
3574 void test_memberWithClassName_field2() { 3298 void test_memberWithClassName_field2() {
3575 Source source = addSource(r''' 3299 Source source = addSource(r'''
3576 class A { 3300 class A {
3577 int z, A, b = 0; 3301 int z, A, b = 0;
3578 }'''); 3302 }''');
3579 computeLibrarySourceErrors(source);
3580 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); 3303 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]);
3581 verify([source]); 3304 verify([source]);
3582 } 3305 }
3583 3306
3584 void test_memberWithClassName_getter() { 3307 void test_memberWithClassName_getter() {
3585 Source source = addSource(r''' 3308 Source source = addSource(r'''
3586 class A { 3309 class A {
3587 get A => 0; 3310 get A => 0;
3588 }'''); 3311 }''');
3589 computeLibrarySourceErrors(source);
3590 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); 3312 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]);
3591 verify([source]); 3313 verify([source]);
3592 } 3314 }
3593 3315
3594 void test_memberWithClassName_method() { 3316 void test_memberWithClassName_method() {
3595 // no test because indistinguishable from constructor 3317 // no test because indistinguishable from constructor
3596 } 3318 }
3597 3319
3598 void test_methodAndGetterWithSameName() { 3320 void test_methodAndGetterWithSameName() {
3599 Source source = addSource(r''' 3321 Source source = addSource(r'''
3600 class A { 3322 class A {
3601 get x => 0; 3323 get x => 0;
3602 x(y) {} 3324 x(y) {}
3603 }'''); 3325 }''');
3604 computeLibrarySourceErrors(source);
3605 assertErrors( 3326 assertErrors(
3606 source, [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME]); 3327 source, [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME]);
3607 verify([source]); 3328 verify([source]);
3608 } 3329 }
3609 3330
3610 void test_mixinDeclaresConstructor_classDeclaration() { 3331 void test_mixinDeclaresConstructor_classDeclaration() {
3611 Source source = addSource(r''' 3332 Source source = addSource(r'''
3612 class A { 3333 class A {
3613 A() {} 3334 A() {}
3614 } 3335 }
3615 class B extends Object with A {}'''); 3336 class B extends Object with A {}''');
3616 computeLibrarySourceErrors(source);
3617 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); 3337 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
3618 verify([source]); 3338 verify([source]);
3619 } 3339 }
3620 3340
3621 void test_mixinDeclaresConstructor_typeAlias() { 3341 void test_mixinDeclaresConstructor_typeAlias() {
3622 Source source = addSource(r''' 3342 Source source = addSource(r'''
3623 class A { 3343 class A {
3624 A() {} 3344 A() {}
3625 } 3345 }
3626 class B = Object with A;'''); 3346 class B = Object with A;''');
3627 computeLibrarySourceErrors(source);
3628 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); 3347 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
3629 verify([source]); 3348 verify([source]);
3630 } 3349 }
3631 3350
3632 void test_mixinDeferredClass() { 3351 void test_mixinDeferredClass() {
3633 resolveWithErrors(<String>[ 3352 resolveWithErrors(<String>[
3634 r''' 3353 r'''
3635 library lib1; 3354 library lib1;
3636 class A {}''', 3355 class A {}''',
3637 r''' 3356 r'''
(...skipping 21 matching lines...) Expand all
3659 } 3378 }
3660 3379
3661 void test_mixinHasNoConstructors_mixinApp() { 3380 void test_mixinHasNoConstructors_mixinApp() {
3662 Source source = addSource(r''' 3381 Source source = addSource(r'''
3663 class B { 3382 class B {
3664 B({x}); 3383 B({x});
3665 } 3384 }
3666 class M {} 3385 class M {}
3667 class C = B with M; 3386 class C = B with M;
3668 '''); 3387 ''');
3669 computeLibrarySourceErrors(source);
3670 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); 3388 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
3671 verify([source]); 3389 verify([source]);
3672 } 3390 }
3673 3391
3674 void test_mixinHasNoConstructors_mixinClass() { 3392 void test_mixinHasNoConstructors_mixinClass() {
3675 Source source = addSource(r''' 3393 Source source = addSource(r'''
3676 class B { 3394 class B {
3677 B({x}); 3395 B({x});
3678 } 3396 }
3679 class M {} 3397 class M {}
3680 class C extends B with M {} 3398 class C extends B with M {}
3681 '''); 3399 ''');
3682 // Note: the implicit call from C's default constructor to B() should not 3400 // Note: the implicit call from C's default constructor to B() should not
3683 // generate a further error (despite the fact that it's not forwarded), 3401 // generate a further error (despite the fact that it's not forwarded),
3684 // since CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job 3402 // since CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job
3685 // of explaining the probem to the user. 3403 // of explaining the probem to the user.
3686 computeLibrarySourceErrors(source);
3687 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); 3404 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
3688 verify([source]); 3405 verify([source]);
3689 } 3406 }
3690 3407
3691 void test_mixinHasNoConstructors_mixinClass_explicitSuperCall() { 3408 void test_mixinHasNoConstructors_mixinClass_explicitSuperCall() {
3692 Source source = addSource(r''' 3409 Source source = addSource(r'''
3693 class B { 3410 class B {
3694 B({x}); 3411 B({x});
3695 } 3412 }
3696 class M {} 3413 class M {}
3697 class C extends B with M { 3414 class C extends B with M {
3698 C() : super(); 3415 C() : super();
3699 } 3416 }
3700 '''); 3417 ''');
3701 // Note: the explicit call from C() to B() should not generate a further 3418 // Note: the explicit call from C() to B() should not generate a further
3702 // error (despite the fact that it's not forwarded), since 3419 // error (despite the fact that it's not forwarded), since
3703 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of 3420 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of
3704 // explaining the error to the user. 3421 // explaining the error to the user.
3705 computeLibrarySourceErrors(source);
3706 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); 3422 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
3707 verify([source]); 3423 verify([source]);
3708 } 3424 }
3709 3425
3710 void test_mixinHasNoConstructors_mixinClass_implicitSuperCall() { 3426 void test_mixinHasNoConstructors_mixinClass_implicitSuperCall() {
3711 Source source = addSource(r''' 3427 Source source = addSource(r'''
3712 class B { 3428 class B {
3713 B({x}); 3429 B({x});
3714 } 3430 }
3715 class M {} 3431 class M {}
3716 class C extends B with M { 3432 class C extends B with M {
3717 C(); 3433 C();
3718 } 3434 }
3719 '''); 3435 ''');
3720 // Note: the implicit call from C() to B() should not generate a further 3436 // Note: the implicit call from C() to B() should not generate a further
3721 // error (despite the fact that it's not forwarded), since 3437 // error (despite the fact that it's not forwarded), since
3722 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of 3438 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of
3723 // explaining the error to the user. 3439 // explaining the error to the user.
3724 computeLibrarySourceErrors(source);
3725 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); 3440 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
3726 verify([source]); 3441 verify([source]);
3727 } 3442 }
3728 3443
3729 void test_mixinHasNoConstructors_mixinClass_namedSuperCall() { 3444 void test_mixinHasNoConstructors_mixinClass_namedSuperCall() {
3730 Source source = addSource(r''' 3445 Source source = addSource(r'''
3731 class B { 3446 class B {
3732 B.named({x}); 3447 B.named({x});
3733 } 3448 }
3734 class M {} 3449 class M {}
3735 class C extends B with M { 3450 class C extends B with M {
3736 C() : super.named(); 3451 C() : super.named();
3737 } 3452 }
3738 '''); 3453 ''');
3739 // Note: the explicit call from C() to B.named() should not generate a 3454 // Note: the explicit call from C() to B.named() should not generate a
3740 // further error (despite the fact that it's not forwarded), since 3455 // further error (despite the fact that it's not forwarded), since
3741 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of 3456 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of
3742 // explaining the error to the user. 3457 // explaining the error to the user.
3743 computeLibrarySourceErrors(source);
3744 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); 3458 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
3745 verify([source]); 3459 verify([source]);
3746 } 3460 }
3747 3461
3748 void test_mixinInheritsFromNotObject_classDeclaration_extends() { 3462 void test_mixinInheritsFromNotObject_classDeclaration_extends() {
3749 Source source = addSource(r''' 3463 Source source = addSource(r'''
3750 class A {} 3464 class A {}
3751 class B extends A {} 3465 class B extends A {}
3752 class C extends Object with B {}'''); 3466 class C extends Object with B {}''');
3753 computeLibrarySourceErrors(source);
3754 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 3467 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
3755 verify([source]); 3468 verify([source]);
3756 } 3469 }
3757 3470
3758 void test_mixinInheritsFromNotObject_classDeclaration_with() { 3471 void test_mixinInheritsFromNotObject_classDeclaration_with() {
3759 Source source = addSource(r''' 3472 Source source = addSource(r'''
3760 class A {} 3473 class A {}
3761 class B extends Object with A {} 3474 class B extends Object with A {}
3762 class C extends Object with B {}'''); 3475 class C extends Object with B {}''');
3763 computeLibrarySourceErrors(source);
3764 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 3476 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
3765 verify([source]); 3477 verify([source]);
3766 } 3478 }
3767 3479
3768 void test_mixinInheritsFromNotObject_typeAlias_extends() { 3480 void test_mixinInheritsFromNotObject_typeAlias_extends() {
3769 Source source = addSource(r''' 3481 Source source = addSource(r'''
3770 class A {} 3482 class A {}
3771 class B extends A {} 3483 class B extends A {}
3772 class C = Object with B;'''); 3484 class C = Object with B;''');
3773 computeLibrarySourceErrors(source);
3774 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 3485 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
3775 verify([source]); 3486 verify([source]);
3776 } 3487 }
3777 3488
3778 void test_mixinInheritsFromNotObject_typeAlias_with() { 3489 void test_mixinInheritsFromNotObject_typeAlias_with() {
3779 Source source = addSource(r''' 3490 Source source = addSource(r'''
3780 class A {} 3491 class A {}
3781 class B extends Object with A {} 3492 class B extends Object with A {}
3782 class C = Object with B;'''); 3493 class C = Object with B;''');
3783 computeLibrarySourceErrors(source);
3784 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 3494 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
3785 verify([source]); 3495 verify([source]);
3786 } 3496 }
3787 3497
3788 void test_mixinOfDisallowedClass_class_bool() { 3498 void test_mixinOfDisallowedClass_class_bool() {
3789 Source source = addSource("class A extends Object with bool {}"); 3499 Source source = addSource("class A extends Object with bool {}");
3790 computeLibrarySourceErrors(source);
3791 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3500 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3792 verify([source]); 3501 verify([source]);
3793 } 3502 }
3794 3503
3795 void test_mixinOfDisallowedClass_class_double() { 3504 void test_mixinOfDisallowedClass_class_double() {
3796 Source source = addSource("class A extends Object with double {}"); 3505 Source source = addSource("class A extends Object with double {}");
3797 computeLibrarySourceErrors(source);
3798 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3506 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3799 verify([source]); 3507 verify([source]);
3800 } 3508 }
3801 3509
3802 void test_mixinOfDisallowedClass_class_int() { 3510 void test_mixinOfDisallowedClass_class_int() {
3803 Source source = addSource("class A extends Object with int {}"); 3511 Source source = addSource("class A extends Object with int {}");
3804 computeLibrarySourceErrors(source);
3805 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3512 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3806 verify([source]); 3513 verify([source]);
3807 } 3514 }
3808 3515
3809 void test_mixinOfDisallowedClass_class_Null() { 3516 void test_mixinOfDisallowedClass_class_Null() {
3810 Source source = addSource("class A extends Object with Null {}"); 3517 Source source = addSource("class A extends Object with Null {}");
3811 computeLibrarySourceErrors(source);
3812 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3518 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3813 verify([source]); 3519 verify([source]);
3814 } 3520 }
3815 3521
3816 void test_mixinOfDisallowedClass_class_num() { 3522 void test_mixinOfDisallowedClass_class_num() {
3817 Source source = addSource("class A extends Object with num {}"); 3523 Source source = addSource("class A extends Object with num {}");
3818 computeLibrarySourceErrors(source);
3819 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3524 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3820 verify([source]); 3525 verify([source]);
3821 } 3526 }
3822 3527
3823 void test_mixinOfDisallowedClass_class_String() { 3528 void test_mixinOfDisallowedClass_class_String() {
3824 Source source = addSource("class A extends Object with String {}"); 3529 Source source = addSource("class A extends Object with String {}");
3825 computeLibrarySourceErrors(source);
3826 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3530 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3827 verify([source]); 3531 verify([source]);
3828 } 3532 }
3829 3533
3830 void test_mixinOfDisallowedClass_classTypeAlias_bool() { 3534 void test_mixinOfDisallowedClass_classTypeAlias_bool() {
3831 Source source = addSource(r''' 3535 Source source = addSource(r'''
3832 class A {} 3536 class A {}
3833 class C = A with bool;'''); 3537 class C = A with bool;''');
3834 computeLibrarySourceErrors(source);
3835 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3538 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3836 verify([source]); 3539 verify([source]);
3837 } 3540 }
3838 3541
3839 void test_mixinOfDisallowedClass_classTypeAlias_double() { 3542 void test_mixinOfDisallowedClass_classTypeAlias_double() {
3840 Source source = addSource(r''' 3543 Source source = addSource(r'''
3841 class A {} 3544 class A {}
3842 class C = A with double;'''); 3545 class C = A with double;''');
3843 computeLibrarySourceErrors(source);
3844 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3546 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3845 verify([source]); 3547 verify([source]);
3846 } 3548 }
3847 3549
3848 void test_mixinOfDisallowedClass_classTypeAlias_int() { 3550 void test_mixinOfDisallowedClass_classTypeAlias_int() {
3849 Source source = addSource(r''' 3551 Source source = addSource(r'''
3850 class A {} 3552 class A {}
3851 class C = A with int;'''); 3553 class C = A with int;''');
3852 computeLibrarySourceErrors(source);
3853 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3554 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3854 verify([source]); 3555 verify([source]);
3855 } 3556 }
3856 3557
3857 void test_mixinOfDisallowedClass_classTypeAlias_Null() { 3558 void test_mixinOfDisallowedClass_classTypeAlias_Null() {
3858 Source source = addSource(r''' 3559 Source source = addSource(r'''
3859 class A {} 3560 class A {}
3860 class C = A with Null;'''); 3561 class C = A with Null;''');
3861 computeLibrarySourceErrors(source);
3862 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3562 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3863 verify([source]); 3563 verify([source]);
3864 } 3564 }
3865 3565
3866 void test_mixinOfDisallowedClass_classTypeAlias_num() { 3566 void test_mixinOfDisallowedClass_classTypeAlias_num() {
3867 Source source = addSource(r''' 3567 Source source = addSource(r'''
3868 class A {} 3568 class A {}
3869 class C = A with num;'''); 3569 class C = A with num;''');
3870 computeLibrarySourceErrors(source);
3871 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3570 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3872 verify([source]); 3571 verify([source]);
3873 } 3572 }
3874 3573
3875 void test_mixinOfDisallowedClass_classTypeAlias_String() { 3574 void test_mixinOfDisallowedClass_classTypeAlias_String() {
3876 Source source = addSource(r''' 3575 Source source = addSource(r'''
3877 class A {} 3576 class A {}
3878 class C = A with String;'''); 3577 class C = A with String;''');
3879 computeLibrarySourceErrors(source);
3880 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); 3578 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]);
3881 verify([source]); 3579 verify([source]);
3882 } 3580 }
3883 3581
3884 void test_mixinOfDisallowedClass_classTypeAlias_String_num() { 3582 void test_mixinOfDisallowedClass_classTypeAlias_String_num() {
3885 Source source = addSource(r''' 3583 Source source = addSource(r'''
3886 class A {} 3584 class A {}
3887 class C = A with String, num;'''); 3585 class C = A with String, num;''');
3888 computeLibrarySourceErrors(source);
3889 assertErrors(source, [ 3586 assertErrors(source, [
3890 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, 3587 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS,
3891 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS 3588 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS
3892 ]); 3589 ]);
3893 verify([source]); 3590 verify([source]);
3894 } 3591 }
3895 3592
3896 void test_mixinOfEnum() { 3593 void test_mixinOfEnum() {
3897 Source source = addSource(r''' 3594 Source source = addSource(r'''
3898 enum E { ONE } 3595 enum E { ONE }
3899 class A extends Object with E {}'''); 3596 class A extends Object with E {}''');
3900 computeLibrarySourceErrors(source);
3901 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_ENUM]); 3597 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_ENUM]);
3902 verify([source]); 3598 verify([source]);
3903 } 3599 }
3904 3600
3905 void test_mixinOfNonClass_class() { 3601 void test_mixinOfNonClass_class() {
3906 Source source = addSource(r''' 3602 Source source = addSource(r'''
3907 int A; 3603 int A;
3908 class B extends Object with A {}'''); 3604 class B extends Object with A {}''');
3909 computeLibrarySourceErrors(source);
3910 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); 3605 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]);
3911 verify([source]); 3606 verify([source]);
3912 } 3607 }
3913 3608
3914 void test_mixinOfNonClass_typeAlias() { 3609 void test_mixinOfNonClass_typeAlias() {
3915 Source source = addSource(r''' 3610 Source source = addSource(r'''
3916 class A {} 3611 class A {}
3917 int B; 3612 int B;
3918 class C = A with B;'''); 3613 class C = A with B;''');
3919 computeLibrarySourceErrors(source);
3920 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); 3614 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]);
3921 verify([source]); 3615 verify([source]);
3922 } 3616 }
3923 3617
3924 void test_mixinReferencesSuper() { 3618 void test_mixinReferencesSuper() {
3925 Source source = addSource(r''' 3619 Source source = addSource(r'''
3926 class A { 3620 class A {
3927 toString() => super.toString(); 3621 toString() => super.toString();
3928 } 3622 }
3929 class B extends Object with A {}'''); 3623 class B extends Object with A {}''');
3930 computeLibrarySourceErrors(source);
3931 assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]); 3624 assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]);
3932 verify([source]); 3625 verify([source]);
3933 } 3626 }
3934 3627
3935 void test_mixinWithNonClassSuperclass_class() { 3628 void test_mixinWithNonClassSuperclass_class() {
3936 Source source = addSource(r''' 3629 Source source = addSource(r'''
3937 int A; 3630 int A;
3938 class B {} 3631 class B {}
3939 class C extends A with B {}'''); 3632 class C extends A with B {}''');
3940 computeLibrarySourceErrors(source);
3941 assertErrors( 3633 assertErrors(
3942 source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]); 3634 source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]);
3943 verify([source]); 3635 verify([source]);
3944 } 3636 }
3945 3637
3946 void test_mixinWithNonClassSuperclass_typeAlias() { 3638 void test_mixinWithNonClassSuperclass_typeAlias() {
3947 Source source = addSource(r''' 3639 Source source = addSource(r'''
3948 int A; 3640 int A;
3949 class B {} 3641 class B {}
3950 class C = A with B;'''); 3642 class C = A with B;''');
3951 computeLibrarySourceErrors(source);
3952 assertErrors( 3643 assertErrors(
3953 source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]); 3644 source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]);
3954 verify([source]); 3645 verify([source]);
3955 } 3646 }
3956 3647
3957 void test_multipleRedirectingConstructorInvocations() { 3648 void test_multipleRedirectingConstructorInvocations() {
3958 Source source = addSource(r''' 3649 Source source = addSource(r'''
3959 class A { 3650 class A {
3960 A() : this.a(), this.b(); 3651 A() : this.a(), this.b();
3961 A.a() {} 3652 A.a() {}
3962 A.b() {} 3653 A.b() {}
3963 }'''); 3654 }''');
3964 computeLibrarySourceErrors(source);
3965 assertErrors(source, 3655 assertErrors(source,
3966 [CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS]); 3656 [CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS]);
3967 verify([source]); 3657 verify([source]);
3968 } 3658 }
3969 3659
3970 void test_multipleSuperInitializers() { 3660 void test_multipleSuperInitializers() {
3971 Source source = addSource(r''' 3661 Source source = addSource(r'''
3972 class A {} 3662 class A {}
3973 class B extends A { 3663 class B extends A {
3974 B() : super(), super() {} 3664 B() : super(), super() {}
3975 }'''); 3665 }''');
3976 computeLibrarySourceErrors(source);
3977 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]); 3666 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]);
3978 verify([source]); 3667 verify([source]);
3979 } 3668 }
3980 3669
3981 void test_nativeClauseInNonSDKCode() { 3670 void test_nativeClauseInNonSDKCode() {
3982 // TODO(jwren) Move this test somewhere else: This test verifies a parser 3671 // TODO(jwren) Move this test somewhere else: This test verifies a parser
3983 // error code is generated through the ErrorVerifier, it is not a 3672 // error code is generated through the ErrorVerifier, it is not a
3984 // CompileTimeErrorCode. 3673 // CompileTimeErrorCode.
3985 Source source = addSource("class A native 'string' {}"); 3674 Source source = addSource("class A native 'string' {}");
3986 computeLibrarySourceErrors(source);
3987 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); 3675 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]);
3988 verify([source]); 3676 verify([source]);
3989 } 3677 }
3990 3678
3991 void test_nativeFunctionBodyInNonSDKCode_function() { 3679 void test_nativeFunctionBodyInNonSDKCode_function() {
3992 // TODO(jwren) Move this test somewhere else: This test verifies a parser 3680 // TODO(jwren) Move this test somewhere else: This test verifies a parser
3993 // error code is generated through the ErrorVerifier, it is not a 3681 // error code is generated through the ErrorVerifier, it is not a
3994 // CompileTimeErrorCode. 3682 // CompileTimeErrorCode.
3995 Source source = addSource("int m(a) native 'string';"); 3683 Source source = addSource("int m(a) native 'string';");
3996 computeLibrarySourceErrors(source);
3997 assertErrors( 3684 assertErrors(
3998 source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]); 3685 source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]);
3999 verify([source]); 3686 verify([source]);
4000 } 3687 }
4001 3688
4002 void test_nativeFunctionBodyInNonSDKCode_method() { 3689 void test_nativeFunctionBodyInNonSDKCode_method() {
4003 // TODO(jwren) Move this test somewhere else: This test verifies a parser 3690 // TODO(jwren) Move this test somewhere else: This test verifies a parser
4004 // error code is generated through the ErrorVerifier, it is not a 3691 // error code is generated through the ErrorVerifier, it is not a
4005 // CompileTimeErrorCode. 3692 // CompileTimeErrorCode.
4006 Source source = addSource(r''' 3693 Source source = addSource(r'''
4007 class A{ 3694 class A{
4008 static int m(a) native 'string'; 3695 static int m(a) native 'string';
4009 }'''); 3696 }''');
4010 computeLibrarySourceErrors(source);
4011 assertErrors( 3697 assertErrors(
4012 source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]); 3698 source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]);
4013 verify([source]); 3699 verify([source]);
4014 } 3700 }
4015 3701
4016 void test_noAnnotationConstructorArguments() { 3702 void test_noAnnotationConstructorArguments() {
4017 Source source = addSource(r''' 3703 Source source = addSource(r'''
4018 class A { 3704 class A {
4019 const A(); 3705 const A();
4020 } 3706 }
4021 @A 3707 @A
4022 main() { 3708 main() {
4023 }'''); 3709 }''');
4024 computeLibrarySourceErrors(source);
4025 assertErrors( 3710 assertErrors(
4026 source, [CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS]); 3711 source, [CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS]);
4027 verify([source]); 3712 verify([source]);
4028 } 3713 }
4029 3714
4030 void test_noDefaultSuperConstructorExplicit() { 3715 void test_noDefaultSuperConstructorExplicit() {
4031 Source source = addSource(r''' 3716 Source source = addSource(r'''
4032 class A { 3717 class A {
4033 A(p); 3718 A(p);
4034 } 3719 }
4035 class B extends A { 3720 class B extends A {
4036 B() {} 3721 B() {}
4037 }'''); 3722 }''');
4038 computeLibrarySourceErrors(source);
4039 assertErrors( 3723 assertErrors(
4040 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); 3724 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]);
4041 verify([source]); 3725 verify([source]);
4042 } 3726 }
4043 3727
4044 void test_noDefaultSuperConstructorExplicit_MixinAppWithDirectSuperCall() { 3728 void test_noDefaultSuperConstructorExplicit_MixinAppWithDirectSuperCall() {
4045 Source source = addSource(r''' 3729 Source source = addSource(r'''
4046 class M {} 3730 class M {}
4047 class B { 3731 class B {
4048 B({x}); 3732 B({x});
4049 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS 3733 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS
4050 } 3734 }
4051 class Mixed = B with M; 3735 class Mixed = B with M;
4052 class C extends Mixed { 3736 class C extends Mixed {
4053 C(x) : super(); 3737 C(x) : super();
4054 } 3738 }
4055 '''); 3739 ''');
4056 computeLibrarySourceErrors(source);
4057 assertErrors(source, 3740 assertErrors(source,
4058 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); 3741 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]);
4059 verify([source]); 3742 verify([source]);
4060 } 3743 }
4061 3744
4062 void test_noDefaultSuperConstructorExplicit_mixinAppWithNamedParam() { 3745 void test_noDefaultSuperConstructorExplicit_mixinAppWithNamedParam() {
4063 Source source = addSource(r''' 3746 Source source = addSource(r'''
4064 class M {} 3747 class M {}
4065 class B { 3748 class B {
4066 B({x}); 3749 B({x});
4067 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS 3750 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS
4068 } 3751 }
4069 class Mixed = B with M; 3752 class Mixed = B with M;
4070 class C extends Mixed { 3753 class C extends Mixed {
4071 C(); 3754 C();
4072 } 3755 }
4073 '''); 3756 ''');
4074 computeLibrarySourceErrors(source);
4075 assertErrors(source, 3757 assertErrors(source,
4076 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); 3758 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]);
4077 verify([source]); 3759 verify([source]);
4078 } 3760 }
4079 3761
4080 void test_noDefaultSuperConstructorExplicit_MixinAppWithNamedSuperCall() { 3762 void test_noDefaultSuperConstructorExplicit_MixinAppWithNamedSuperCall() {
4081 Source source = addSource(r''' 3763 Source source = addSource(r'''
4082 class M {} 3764 class M {}
4083 class B { 3765 class B {
4084 B.named({x}); 3766 B.named({x});
4085 B.named2(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS 3767 B.named2(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS
4086 } 3768 }
4087 class Mixed = B with M; 3769 class Mixed = B with M;
4088 class C extends Mixed { 3770 class C extends Mixed {
4089 C(x) : super.named(); 3771 C(x) : super.named();
4090 } 3772 }
4091 '''); 3773 ''');
4092 computeLibrarySourceErrors(source);
4093 assertErrors( 3774 assertErrors(
4094 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); 3775 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]);
4095 // Don't verify since call to super.named() can't be resolved. 3776 // Don't verify since call to super.named() can't be resolved.
4096 } 3777 }
4097 3778
4098 void test_noDefaultSuperConstructorExplicit_mixinAppWithOptionalParam() { 3779 void test_noDefaultSuperConstructorExplicit_mixinAppWithOptionalParam() {
4099 Source source = addSource(r''' 3780 Source source = addSource(r'''
4100 class M {} 3781 class M {}
4101 class B { 3782 class B {
4102 B([x]); 3783 B([x]);
4103 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS 3784 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS
4104 } 3785 }
4105 class Mixed = B with M; 3786 class Mixed = B with M;
4106 class C extends Mixed { 3787 class C extends Mixed {
4107 C(); 3788 C();
4108 } 3789 }
4109 '''); 3790 ''');
4110 computeLibrarySourceErrors(source);
4111 assertErrors(source, 3791 assertErrors(source,
4112 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); 3792 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]);
4113 verify([source]); 3793 verify([source]);
4114 } 3794 }
4115 3795
4116 void test_noDefaultSuperConstructorExplicit_MixinWithDirectSuperCall() { 3796 void test_noDefaultSuperConstructorExplicit_MixinWithDirectSuperCall() {
4117 Source source = addSource(r''' 3797 Source source = addSource(r'''
4118 class M {} 3798 class M {}
4119 class B { 3799 class B {
4120 B({x}); 3800 B({x});
4121 B.other(); 3801 B.other();
4122 } 3802 }
4123 class C extends B with M { 3803 class C extends B with M {
4124 C(x) : super(); 3804 C(x) : super();
4125 } 3805 }
4126 '''); 3806 ''');
4127 computeLibrarySourceErrors(source);
4128 assertErrors(source, 3807 assertErrors(source,
4129 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); 3808 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]);
4130 verify([source]); 3809 verify([source]);
4131 } 3810 }
4132 3811
4133 void test_noDefaultSuperConstructorExplicit_mixinWithNamedParam() { 3812 void test_noDefaultSuperConstructorExplicit_mixinWithNamedParam() {
4134 Source source = addSource(r''' 3813 Source source = addSource(r'''
4135 class M {} 3814 class M {}
4136 class B { 3815 class B {
4137 B({x}); 3816 B({x});
4138 B.named(); 3817 B.named();
4139 } 3818 }
4140 class C extends B with M { 3819 class C extends B with M {
4141 C(); 3820 C();
4142 } 3821 }
4143 '''); 3822 ''');
4144 computeLibrarySourceErrors(source);
4145 assertErrors( 3823 assertErrors(
4146 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); 3824 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]);
4147 verify([source]); 3825 verify([source]);
4148 } 3826 }
4149 3827
4150 void test_noDefaultSuperConstructorExplicit_MixinWithNamedSuperCall() { 3828 void test_noDefaultSuperConstructorExplicit_MixinWithNamedSuperCall() {
4151 Source source = addSource(r''' 3829 Source source = addSource(r'''
4152 class M {} 3830 class M {}
4153 class B { 3831 class B {
4154 B.named({x}); 3832 B.named({x});
4155 B.other(); 3833 B.other();
4156 } 3834 }
4157 class C extends B with M { 3835 class C extends B with M {
4158 C(x) : super.named(); 3836 C(x) : super.named();
4159 } 3837 }
4160 '''); 3838 ''');
4161 computeLibrarySourceErrors(source);
4162 assertErrors( 3839 assertErrors(
4163 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); 3840 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]);
4164 // Don't verify since call to super.named() can't be resolved. 3841 // Don't verify since call to super.named() can't be resolved.
4165 } 3842 }
4166 3843
4167 void test_noDefaultSuperConstructorExplicit_mixinWithOptionalParam() { 3844 void test_noDefaultSuperConstructorExplicit_mixinWithOptionalParam() {
4168 Source source = addSource(r''' 3845 Source source = addSource(r'''
4169 class M {} 3846 class M {}
4170 class B { 3847 class B {
4171 B([x]); 3848 B([x]);
4172 B.other(); 3849 B.other();
4173 } 3850 }
4174 class C extends B with M { 3851 class C extends B with M {
4175 C(); 3852 C();
4176 } 3853 }
4177 '''); 3854 ''');
4178 computeLibrarySourceErrors(source);
4179 assertErrors( 3855 assertErrors(
4180 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); 3856 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]);
4181 verify([source]); 3857 verify([source]);
4182 } 3858 }
4183 3859
4184 void test_noDefaultSuperConstructorImplicit_mixinAppWithNamedParam() { 3860 void test_noDefaultSuperConstructorImplicit_mixinAppWithNamedParam() {
4185 Source source = addSource(r''' 3861 Source source = addSource(r'''
4186 class M {} 3862 class M {}
4187 class B { 3863 class B {
4188 B({x}); 3864 B({x});
4189 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS 3865 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS
4190 } 3866 }
4191 class Mixed = B with M; 3867 class Mixed = B with M;
4192 class C extends Mixed {} 3868 class C extends Mixed {}
4193 '''); 3869 ''');
4194 computeLibrarySourceErrors(source);
4195 assertErrors( 3870 assertErrors(
4196 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 3871 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
4197 verify([source]); 3872 verify([source]);
4198 } 3873 }
4199 3874
4200 void test_noDefaultSuperConstructorImplicit_mixinAppWithOptionalParam() { 3875 void test_noDefaultSuperConstructorImplicit_mixinAppWithOptionalParam() {
4201 Source source = addSource(r''' 3876 Source source = addSource(r'''
4202 class M {} 3877 class M {}
4203 class B { 3878 class B {
4204 B([x]); 3879 B([x]);
4205 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS 3880 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS
4206 } 3881 }
4207 class Mixed = B with M; 3882 class Mixed = B with M;
4208 class C extends Mixed {} 3883 class C extends Mixed {}
4209 '''); 3884 ''');
4210 computeLibrarySourceErrors(source);
4211 assertErrors( 3885 assertErrors(
4212 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 3886 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
4213 verify([source]); 3887 verify([source]);
4214 } 3888 }
4215 3889
4216 void test_noDefaultSuperConstructorImplicit_mixinWithNamedParam() { 3890 void test_noDefaultSuperConstructorImplicit_mixinWithNamedParam() {
4217 Source source = addSource(r''' 3891 Source source = addSource(r'''
4218 class M {} 3892 class M {}
4219 class B { 3893 class B {
4220 B({x}); 3894 B({x});
4221 B.other(); 3895 B.other();
4222 } 3896 }
4223 class C extends B with M {} 3897 class C extends B with M {}
4224 '''); 3898 ''');
4225 computeLibrarySourceErrors(source);
4226 assertErrors( 3899 assertErrors(
4227 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 3900 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
4228 verify([source]); 3901 verify([source]);
4229 } 3902 }
4230 3903
4231 void test_noDefaultSuperConstructorImplicit_mixinWithOptionalParam() { 3904 void test_noDefaultSuperConstructorImplicit_mixinWithOptionalParam() {
4232 Source source = addSource(r''' 3905 Source source = addSource(r'''
4233 class M {} 3906 class M {}
4234 class B { 3907 class B {
4235 B([x]); 3908 B([x]);
4236 B.other(); 3909 B.other();
4237 } 3910 }
4238 class C extends B with M {} 3911 class C extends B with M {}
4239 '''); 3912 ''');
4240 computeLibrarySourceErrors(source);
4241 assertErrors( 3913 assertErrors(
4242 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 3914 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
4243 verify([source]); 3915 verify([source]);
4244 } 3916 }
4245 3917
4246 void test_noDefaultSuperConstructorImplicit_superHasParameters() { 3918 void test_noDefaultSuperConstructorImplicit_superHasParameters() {
4247 Source source = addSource(r''' 3919 Source source = addSource(r'''
4248 class A { 3920 class A {
4249 A(p); 3921 A(p);
4250 } 3922 }
4251 class B extends A { 3923 class B extends A {
4252 }'''); 3924 }''');
4253 computeLibrarySourceErrors(source);
4254 assertErrors( 3925 assertErrors(
4255 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 3926 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
4256 verify([source]); 3927 verify([source]);
4257 } 3928 }
4258 3929
4259 void test_noDefaultSuperConstructorImplicit_superOnlyNamed() { 3930 void test_noDefaultSuperConstructorImplicit_superOnlyNamed() {
4260 Source source = addSource(r''' 3931 Source source = addSource(r'''
4261 class A { A.named() {} } 3932 class A { A.named() {} }
4262 class B extends A {}'''); 3933 class B extends A {}''');
4263 computeLibrarySourceErrors(source);
4264 assertErrors( 3934 assertErrors(
4265 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 3935 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
4266 verify([source]); 3936 verify([source]);
4267 } 3937 }
4268 3938
4269 void test_nonConstantAnnotationConstructor_named() { 3939 void test_nonConstantAnnotationConstructor_named() {
4270 Source source = addSource(r''' 3940 Source source = addSource(r'''
4271 class A { 3941 class A {
4272 A.fromInt() {} 3942 A.fromInt() {}
4273 } 3943 }
4274 @A.fromInt() 3944 @A.fromInt()
4275 main() { 3945 main() {
4276 }'''); 3946 }''');
4277 computeLibrarySourceErrors(source);
4278 assertErrors( 3947 assertErrors(
4279 source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR]); 3948 source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR]);
4280 verify([source]); 3949 verify([source]);
4281 } 3950 }
4282 3951
4283 void test_nonConstantAnnotationConstructor_unnamed() { 3952 void test_nonConstantAnnotationConstructor_unnamed() {
4284 Source source = addSource(r''' 3953 Source source = addSource(r'''
4285 class A { 3954 class A {
4286 A() {} 3955 A() {}
4287 } 3956 }
4288 @A() 3957 @A()
4289 main() { 3958 main() {
4290 }'''); 3959 }''');
4291 computeLibrarySourceErrors(source);
4292 assertErrors( 3960 assertErrors(
4293 source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR]); 3961 source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR]);
4294 verify([source]); 3962 verify([source]);
4295 } 3963 }
4296 3964
4297 void test_nonConstantDefaultValue_function_named() { 3965 void test_nonConstantDefaultValue_function_named() {
4298 Source source = addSource(r''' 3966 Source source = addSource(r'''
4299 int y; 3967 int y;
4300 f({x : y}) {}'''); 3968 f({x : y}) {}''');
4301 computeLibrarySourceErrors(source);
4302 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3969 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
4303 verify([source]); 3970 verify([source]);
4304 } 3971 }
4305 3972
4306 void test_nonConstantDefaultValue_function_positional() { 3973 void test_nonConstantDefaultValue_function_positional() {
4307 Source source = addSource(r''' 3974 Source source = addSource(r'''
4308 int y; 3975 int y;
4309 f([x = y]) {}'''); 3976 f([x = y]) {}''');
4310 computeLibrarySourceErrors(source);
4311 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3977 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
4312 verify([source]); 3978 verify([source]);
4313 } 3979 }
4314 3980
4315 void test_nonConstantDefaultValue_inConstructor_named() { 3981 void test_nonConstantDefaultValue_inConstructor_named() {
4316 Source source = addSource(r''' 3982 Source source = addSource(r'''
4317 class A { 3983 class A {
4318 int y; 3984 int y;
4319 A({x : y}) {} 3985 A({x : y}) {}
4320 }'''); 3986 }''');
4321 computeLibrarySourceErrors(source);
4322 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3987 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
4323 verify([source]); 3988 verify([source]);
4324 } 3989 }
4325 3990
4326 void test_nonConstantDefaultValue_inConstructor_positional() { 3991 void test_nonConstantDefaultValue_inConstructor_positional() {
4327 Source source = addSource(r''' 3992 Source source = addSource(r'''
4328 class A { 3993 class A {
4329 int y; 3994 int y;
4330 A([x = y]) {} 3995 A([x = y]) {}
4331 }'''); 3996 }''');
4332 computeLibrarySourceErrors(source);
4333 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 3997 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
4334 verify([source]); 3998 verify([source]);
4335 } 3999 }
4336 4000
4337 void test_nonConstantDefaultValue_method_named() { 4001 void test_nonConstantDefaultValue_method_named() {
4338 Source source = addSource(r''' 4002 Source source = addSource(r'''
4339 class A { 4003 class A {
4340 int y; 4004 int y;
4341 m({x : y}) {} 4005 m({x : y}) {}
4342 }'''); 4006 }''');
4343 computeLibrarySourceErrors(source);
4344 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 4007 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
4345 verify([source]); 4008 verify([source]);
4346 } 4009 }
4347 4010
4348 void test_nonConstantDefaultValue_method_positional() { 4011 void test_nonConstantDefaultValue_method_positional() {
4349 Source source = addSource(r''' 4012 Source source = addSource(r'''
4350 class A { 4013 class A {
4351 int y; 4014 int y;
4352 m([x = y]) {} 4015 m([x = y]) {}
4353 }'''); 4016 }''');
4354 computeLibrarySourceErrors(source);
4355 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); 4017 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
4356 verify([source]); 4018 verify([source]);
4357 } 4019 }
4358 4020
4359 void test_nonConstantDefaultValueFromDeferredLibrary() { 4021 void test_nonConstantDefaultValueFromDeferredLibrary() {
4360 resolveWithErrors(<String>[ 4022 resolveWithErrors(<String>[
4361 r''' 4023 r'''
4362 library lib1; 4024 library lib1;
4363 const V = 1;''', 4025 const V = 1;''',
4364 r''' 4026 r'''
(...skipping 20 matching lines...) Expand all
4385 } 4047 }
4386 4048
4387 void test_nonConstCaseExpression() { 4049 void test_nonConstCaseExpression() {
4388 Source source = addSource(r''' 4050 Source source = addSource(r'''
4389 f(int p, int q) { 4051 f(int p, int q) {
4390 switch (p) { 4052 switch (p) {
4391 case 3 + q: 4053 case 3 + q:
4392 break; 4054 break;
4393 } 4055 }
4394 }'''); 4056 }''');
4395 computeLibrarySourceErrors(source);
4396 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION]); 4057 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION]);
4397 verify([source]); 4058 verify([source]);
4398 } 4059 }
4399 4060
4400 void test_nonConstCaseExpressionFromDeferredLibrary() { 4061 void test_nonConstCaseExpressionFromDeferredLibrary() {
4401 resolveWithErrors(<String>[ 4062 resolveWithErrors(<String>[
4402 r''' 4063 r'''
4403 library lib1; 4064 library lib1;
4404 const int c = 1;''', 4065 const int c = 1;''',
4405 r''' 4066 r'''
(...skipping 27 matching lines...) Expand all
4433 ], <ErrorCode>[ 4094 ], <ErrorCode>[
4434 CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY 4095 CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY
4435 ]); 4096 ]);
4436 } 4097 }
4437 4098
4438 void test_nonConstListElement() { 4099 void test_nonConstListElement() {
4439 Source source = addSource(r''' 4100 Source source = addSource(r'''
4440 f(a) { 4101 f(a) {
4441 return const [a]; 4102 return const [a];
4442 }'''); 4103 }''');
4443 computeLibrarySourceErrors(source);
4444 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]); 4104 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
4445 verify([source]); 4105 verify([source]);
4446 } 4106 }
4447 4107
4448 void test_nonConstListElementFromDeferredLibrary() { 4108 void test_nonConstListElementFromDeferredLibrary() {
4449 resolveWithErrors(<String>[ 4109 resolveWithErrors(<String>[
4450 r''' 4110 r'''
4451 library lib1; 4111 library lib1;
4452 const int c = 1;''', 4112 const int c = 1;''',
4453 r''' 4113 r'''
(...skipping 21 matching lines...) Expand all
4475 ], <ErrorCode>[ 4135 ], <ErrorCode>[
4476 CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY 4136 CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY
4477 ]); 4137 ]);
4478 } 4138 }
4479 4139
4480 void test_nonConstMapAsExpressionStatement_begin() { 4140 void test_nonConstMapAsExpressionStatement_begin() {
4481 Source source = addSource(r''' 4141 Source source = addSource(r'''
4482 f() { 4142 f() {
4483 {'a' : 0, 'b' : 1}.length; 4143 {'a' : 0, 'b' : 1}.length;
4484 }'''); 4144 }''');
4485 computeLibrarySourceErrors(source);
4486 assertErrors( 4145 assertErrors(
4487 source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]); 4146 source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]);
4488 verify([source]); 4147 verify([source]);
4489 } 4148 }
4490 4149
4491 void test_nonConstMapAsExpressionStatement_only() { 4150 void test_nonConstMapAsExpressionStatement_only() {
4492 Source source = addSource(r''' 4151 Source source = addSource(r'''
4493 f() { 4152 f() {
4494 {'a' : 0, 'b' : 1}; 4153 {'a' : 0, 'b' : 1};
4495 }'''); 4154 }''');
4496 computeLibrarySourceErrors(source);
4497 assertErrors( 4155 assertErrors(
4498 source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]); 4156 source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]);
4499 verify([source]); 4157 verify([source]);
4500 } 4158 }
4501 4159
4502 void test_nonConstMapKey() { 4160 void test_nonConstMapKey() {
4503 Source source = addSource(r''' 4161 Source source = addSource(r'''
4504 f(a) { 4162 f(a) {
4505 return const {a : 0}; 4163 return const {a : 0};
4506 }'''); 4164 }''');
4507 computeLibrarySourceErrors(source);
4508 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]); 4165 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]);
4509 verify([source]); 4166 verify([source]);
4510 } 4167 }
4511 4168
4512 void test_nonConstMapKeyFromDeferredLibrary() { 4169 void test_nonConstMapKeyFromDeferredLibrary() {
4513 resolveWithErrors(<String>[ 4170 resolveWithErrors(<String>[
4514 r''' 4171 r'''
4515 library lib1; 4172 library lib1;
4516 const int c = 1;''', 4173 const int c = 1;''',
4517 r''' 4174 r'''
(...skipping 21 matching lines...) Expand all
4539 ], <ErrorCode>[ 4196 ], <ErrorCode>[
4540 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY 4197 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY
4541 ]); 4198 ]);
4542 } 4199 }
4543 4200
4544 void test_nonConstMapValue() { 4201 void test_nonConstMapValue() {
4545 Source source = addSource(r''' 4202 Source source = addSource(r'''
4546 f(a) { 4203 f(a) {
4547 return const {'a' : a}; 4204 return const {'a' : a};
4548 }'''); 4205 }''');
4549 computeLibrarySourceErrors(source);
4550 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]); 4206 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]);
4551 verify([source]); 4207 verify([source]);
4552 } 4208 }
4553 4209
4554 void test_nonConstMapValueFromDeferredLibrary() { 4210 void test_nonConstMapValueFromDeferredLibrary() {
4555 resolveWithErrors(<String>[ 4211 resolveWithErrors(<String>[
4556 r''' 4212 r'''
4557 library lib1; 4213 library lib1;
4558 const int c = 1;''', 4214 const int c = 1;''',
4559 r''' 4215 r'''
(...skipping 22 matching lines...) Expand all
4582 CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY 4238 CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY
4583 ]); 4239 ]);
4584 } 4240 }
4585 4241
4586 void test_nonConstValueInInitializer_assert_condition() { 4242 void test_nonConstValueInInitializer_assert_condition() {
4587 resetWithOptions(new AnalysisOptionsImpl()..enableAssertInitializer = true); 4243 resetWithOptions(new AnalysisOptionsImpl()..enableAssertInitializer = true);
4588 Source source = addSource(r''' 4244 Source source = addSource(r'''
4589 class A { 4245 class A {
4590 const A(int i) : assert(i.isNegative); 4246 const A(int i) : assert(i.isNegative);
4591 }'''); 4247 }''');
4592 computeLibrarySourceErrors(source);
4593 assertErrors( 4248 assertErrors(
4594 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); 4249 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]);
4595 verify([source]); 4250 verify([source]);
4596 } 4251 }
4597 4252
4598 void test_nonConstValueInInitializer_assert_message() { 4253 void test_nonConstValueInInitializer_assert_message() {
4599 resetWithOptions(new AnalysisOptionsImpl()..enableAssertInitializer = true); 4254 resetWithOptions(new AnalysisOptionsImpl()..enableAssertInitializer = true);
4600 Source source = addSource(r''' 4255 Source source = addSource(r'''
4601 class A { 4256 class A {
4602 const A(int i) : assert(i < 0, 'isNegative = ${i.isNegative}'); 4257 const A(int i) : assert(i < 0, 'isNegative = ${i.isNegative}');
4603 }'''); 4258 }''');
4604 computeLibrarySourceErrors(source);
4605 assertErrors( 4259 assertErrors(
4606 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); 4260 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]);
4607 verify([source]); 4261 verify([source]);
4608 } 4262 }
4609 4263
4610 void test_nonConstValueInInitializer_binary_notBool_left() { 4264 void test_nonConstValueInInitializer_binary_notBool_left() {
4611 Source source = addSource(r''' 4265 Source source = addSource(r'''
4612 class A { 4266 class A {
4613 final bool a; 4267 final bool a;
4614 const A(String p) : a = p && true; 4268 const A(String p) : a = p && true;
4615 }'''); 4269 }''');
4616 computeLibrarySourceErrors(source);
4617 assertErrors(source, [ 4270 assertErrors(source, [
4618 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 4271 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
4619 StaticTypeWarningCode.NON_BOOL_OPERAND 4272 StaticTypeWarningCode.NON_BOOL_OPERAND
4620 ]); 4273 ]);
4621 verify([source]); 4274 verify([source]);
4622 } 4275 }
4623 4276
4624 void test_nonConstValueInInitializer_binary_notBool_right() { 4277 void test_nonConstValueInInitializer_binary_notBool_right() {
4625 Source source = addSource(r''' 4278 Source source = addSource(r'''
4626 class A { 4279 class A {
4627 final bool a; 4280 final bool a;
4628 const A(String p) : a = true && p; 4281 const A(String p) : a = true && p;
4629 }'''); 4282 }''');
4630 computeLibrarySourceErrors(source);
4631 assertErrors(source, [ 4283 assertErrors(source, [
4632 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 4284 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
4633 StaticTypeWarningCode.NON_BOOL_OPERAND 4285 StaticTypeWarningCode.NON_BOOL_OPERAND
4634 ]); 4286 ]);
4635 verify([source]); 4287 verify([source]);
4636 } 4288 }
4637 4289
4638 void test_nonConstValueInInitializer_binary_notInt() { 4290 void test_nonConstValueInInitializer_binary_notInt() {
4639 Source source = addSource(r''' 4291 Source source = addSource(r'''
4640 class A { 4292 class A {
4641 final int a; 4293 final int a;
4642 const A(String p) : a = 5 & p; 4294 const A(String p) : a = 5 & p;
4643 }'''); 4295 }''');
4644 computeLibrarySourceErrors(source);
4645 assertErrors(source, [ 4296 assertErrors(source, [
4646 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, 4297 CompileTimeErrorCode.CONST_EVAL_TYPE_INT,
4647 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE 4298 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE
4648 ]); 4299 ]);
4649 verify([source]); 4300 verify([source]);
4650 } 4301 }
4651 4302
4652 void test_nonConstValueInInitializer_binary_notNum() { 4303 void test_nonConstValueInInitializer_binary_notNum() {
4653 Source source = addSource(r''' 4304 Source source = addSource(r'''
4654 class A { 4305 class A {
4655 final int a; 4306 final int a;
4656 const A(String p) : a = 5 + p; 4307 const A(String p) : a = 5 + p;
4657 }'''); 4308 }''');
4658 computeLibrarySourceErrors(source);
4659 assertErrors(source, [ 4309 assertErrors(source, [
4660 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, 4310 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM,
4661 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE 4311 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE
4662 ]); 4312 ]);
4663 verify([source]); 4313 verify([source]);
4664 } 4314 }
4665 4315
4666 void test_nonConstValueInInitializer_field() { 4316 void test_nonConstValueInInitializer_field() {
4667 Source source = addSource(r''' 4317 Source source = addSource(r'''
4668 class A { 4318 class A {
4669 static int C; 4319 static int C;
4670 final int a; 4320 final int a;
4671 const A() : a = C; 4321 const A() : a = C;
4672 }'''); 4322 }''');
4673 computeLibrarySourceErrors(source);
4674 assertErrors( 4323 assertErrors(
4675 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); 4324 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]);
4676 verify([source]); 4325 verify([source]);
4677 } 4326 }
4678 4327
4679 void test_nonConstValueInInitializer_instanceCreation() { 4328 void test_nonConstValueInInitializer_instanceCreation() {
4680 Source source = addSource(r''' 4329 Source source = addSource(r'''
4681 class A { 4330 class A {
4682 A(); 4331 A();
4683 } 4332 }
4684 class B { 4333 class B {
4685 const B() : a = new A(); 4334 const B() : a = new A();
4686 final a; 4335 final a;
4687 } 4336 }
4688 var b = const B();'''); 4337 var b = const B();''');
4689 computeLibrarySourceErrors(source);
4690 // TODO(paulberry): the error INVALID_CONSTAT is redundant and ought to be 4338 // TODO(paulberry): the error INVALID_CONSTAT is redundant and ought to be
4691 // suppressed. 4339 // suppressed.
4692 assertErrors(source, [ 4340 assertErrors(source, [
4693 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER, 4341 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER,
4694 CompileTimeErrorCode.INVALID_CONSTANT 4342 CompileTimeErrorCode.INVALID_CONSTANT
4695 ]); 4343 ]);
4696 verify([source]); 4344 verify([source]);
4697 } 4345 }
4698 4346
4699 void test_nonConstValueInInitializer_redirecting() { 4347 void test_nonConstValueInInitializer_redirecting() {
4700 Source source = addSource(r''' 4348 Source source = addSource(r'''
4701 class A { 4349 class A {
4702 static var C; 4350 static var C;
4703 const A.named(p); 4351 const A.named(p);
4704 const A() : this.named(C); 4352 const A() : this.named(C);
4705 }'''); 4353 }''');
4706 computeLibrarySourceErrors(source);
4707 assertErrors( 4354 assertErrors(
4708 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); 4355 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]);
4709 verify([source]); 4356 verify([source]);
4710 } 4357 }
4711 4358
4712 void test_nonConstValueInInitializer_super() { 4359 void test_nonConstValueInInitializer_super() {
4713 Source source = addSource(r''' 4360 Source source = addSource(r'''
4714 class A { 4361 class A {
4715 const A(p); 4362 const A(p);
4716 } 4363 }
4717 class B extends A { 4364 class B extends A {
4718 static var C; 4365 static var C;
4719 const B() : super(C); 4366 const B() : super(C);
4720 }'''); 4367 }''');
4721 computeLibrarySourceErrors(source);
4722 assertErrors( 4368 assertErrors(
4723 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); 4369 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]);
4724 verify([source]); 4370 verify([source]);
4725 } 4371 }
4726 4372
4727 void test_nonConstValueInInitializerFromDeferredLibrary_field() { 4373 void test_nonConstValueInInitializerFromDeferredLibrary_field() {
4728 resolveWithErrors(<String>[ 4374 resolveWithErrors(<String>[
4729 r''' 4375 r'''
4730 library lib1; 4376 library lib1;
4731 const int c = 1;''', 4377 const int c = 1;''',
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
4799 } 4445 }
4800 4446
4801 void test_nonGenerativeConstructor_explicit() { 4447 void test_nonGenerativeConstructor_explicit() {
4802 Source source = addSource(r''' 4448 Source source = addSource(r'''
4803 class A { 4449 class A {
4804 factory A.named() => null; 4450 factory A.named() => null;
4805 } 4451 }
4806 class B extends A { 4452 class B extends A {
4807 B() : super.named(); 4453 B() : super.named();
4808 }'''); 4454 }''');
4809 computeLibrarySourceErrors(source);
4810 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); 4455 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]);
4811 verify([source]); 4456 verify([source]);
4812 } 4457 }
4813 4458
4814 void test_nonGenerativeConstructor_implicit() { 4459 void test_nonGenerativeConstructor_implicit() {
4815 Source source = addSource(r''' 4460 Source source = addSource(r'''
4816 class A { 4461 class A {
4817 factory A() => null; 4462 factory A() => null;
4818 } 4463 }
4819 class B extends A { 4464 class B extends A {
4820 B(); 4465 B();
4821 }'''); 4466 }''');
4822 computeLibrarySourceErrors(source);
4823 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); 4467 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]);
4824 verify([source]); 4468 verify([source]);
4825 } 4469 }
4826 4470
4827 void test_nonGenerativeConstructor_implicit2() { 4471 void test_nonGenerativeConstructor_implicit2() {
4828 Source source = addSource(r''' 4472 Source source = addSource(r'''
4829 class A { 4473 class A {
4830 factory A() => null; 4474 factory A() => null;
4831 } 4475 }
4832 class B extends A { 4476 class B extends A {
4833 }'''); 4477 }''');
4834 computeLibrarySourceErrors(source);
4835 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); 4478 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]);
4836 verify([source]); 4479 verify([source]);
4837 } 4480 }
4838 4481
4839 void test_notEnoughRequiredArguments_const() { 4482 void test_notEnoughRequiredArguments_const() {
4840 Source source = addSource(r''' 4483 Source source = addSource(r'''
4841 class A { 4484 class A {
4842 const A(int p); 4485 const A(int p);
4843 } 4486 }
4844 main() { 4487 main() {
4845 const A(); 4488 const A();
4846 }'''); 4489 }''');
4847 computeLibrarySourceErrors(source);
4848 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); 4490 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]);
4849 verify([source]); 4491 verify([source]);
4850 } 4492 }
4851 4493
4852 void test_notEnoughRequiredArguments_const_super() { 4494 void test_notEnoughRequiredArguments_const_super() {
4853 Source source = addSource(r''' 4495 Source source = addSource(r'''
4854 class A { 4496 class A {
4855 const A(int p); 4497 const A(int p);
4856 } 4498 }
4857 class B extends A { 4499 class B extends A {
4858 const B() : super(); 4500 const B() : super();
4859 }'''); 4501 }''');
4860 computeLibrarySourceErrors(source);
4861 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); 4502 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]);
4862 verify([source]); 4503 verify([source]);
4863 } 4504 }
4864 4505
4865 void test_optionalParameterInOperator_named() { 4506 void test_optionalParameterInOperator_named() {
4866 Source source = addSource(r''' 4507 Source source = addSource(r'''
4867 class A { 4508 class A {
4868 operator +({p}) {} 4509 operator +({p}) {}
4869 }'''); 4510 }''');
4870 computeLibrarySourceErrors(source);
4871 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); 4511 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]);
4872 verify([source]); 4512 verify([source]);
4873 } 4513 }
4874 4514
4875 void test_optionalParameterInOperator_positional() { 4515 void test_optionalParameterInOperator_positional() {
4876 Source source = addSource(r''' 4516 Source source = addSource(r'''
4877 class A { 4517 class A {
4878 operator +([p]) {} 4518 operator +([p]) {}
4879 }'''); 4519 }''');
4880 computeLibrarySourceErrors(source);
4881 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); 4520 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]);
4882 verify([source]); 4521 verify([source]);
4883 } 4522 }
4884 4523
4885 void test_partOfNonPart() { 4524 void test_partOfNonPart() {
4886 Source source = addSource(r''' 4525 Source source = addSource(r'''
4887 library l1; 4526 library l1;
4888 part 'l2.dart';'''); 4527 part 'l2.dart';''');
4889 addNamedSource("/l2.dart", "library l2;"); 4528 addNamedSource("/l2.dart", "library l2;");
4890 computeLibrarySourceErrors(source);
4891 assertErrors(source, [CompileTimeErrorCode.PART_OF_NON_PART]); 4529 assertErrors(source, [CompileTimeErrorCode.PART_OF_NON_PART]);
4892 verify([source]); 4530 verify([source]);
4893 } 4531 }
4894 4532
4895 void test_partOfNonPart_self() { 4533 void test_partOfNonPart_self() {
4896 Source source = addSource(r''' 4534 Source source = addSource(r'''
4897 library lib; 4535 library lib;
4898 part 'test.dart';'''); 4536 part 'test.dart';''');
4899 computeLibrarySourceErrors(source);
4900 assertErrors(source, [CompileTimeErrorCode.PART_OF_NON_PART]); 4537 assertErrors(source, [CompileTimeErrorCode.PART_OF_NON_PART]);
4901 verify([source]); 4538 verify([source]);
4902 } 4539 }
4903 4540
4904 void test_prefix_assignment_compound_in_method() { 4541 void test_prefix_assignment_compound_in_method() {
4905 addNamedSource('/lib.dart', 'library lib;'); 4542 addNamedSource('/lib.dart', 'library lib;');
4906 Source source = addSource(''' 4543 Source source = addSource('''
4907 import 'lib.dart' as p; 4544 import 'lib.dart' as p;
4908 class C { 4545 class C {
4909 f() { 4546 f() {
4910 p += 1; 4547 p += 1;
4911 } 4548 }
4912 } 4549 }
4913 '''); 4550 ''');
4914 computeLibrarySourceErrors(source);
4915 assertErrors( 4551 assertErrors(
4916 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4552 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
4917 verify([source]); 4553 verify([source]);
4918 } 4554 }
4919 4555
4920 void test_prefix_assignment_compound_not_in_method() { 4556 void test_prefix_assignment_compound_not_in_method() {
4921 addNamedSource('/lib.dart', 'library lib;'); 4557 addNamedSource('/lib.dart', 'library lib;');
4922 Source source = addSource(''' 4558 Source source = addSource('''
4923 import 'lib.dart' as p; 4559 import 'lib.dart' as p;
4924 f() { 4560 f() {
4925 p += 1; 4561 p += 1;
4926 } 4562 }
4927 '''); 4563 ''');
4928 computeLibrarySourceErrors(source);
4929 assertErrors( 4564 assertErrors(
4930 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4565 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
4931 verify([source]); 4566 verify([source]);
4932 } 4567 }
4933 4568
4934 void test_prefix_assignment_in_method() { 4569 void test_prefix_assignment_in_method() {
4935 addNamedSource('/lib.dart', 'library lib;'); 4570 addNamedSource('/lib.dart', 'library lib;');
4936 Source source = addSource(''' 4571 Source source = addSource('''
4937 import 'lib.dart' as p; 4572 import 'lib.dart' as p;
4938 class C { 4573 class C {
4939 f() { 4574 f() {
4940 p = 1; 4575 p = 1;
4941 } 4576 }
4942 } 4577 }
4943 '''); 4578 ''');
4944 computeLibrarySourceErrors(source);
4945 assertErrors( 4579 assertErrors(
4946 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4580 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
4947 verify([source]); 4581 verify([source]);
4948 } 4582 }
4949 4583
4950 void test_prefix_assignment_not_in_method() { 4584 void test_prefix_assignment_not_in_method() {
4951 addNamedSource('/lib.dart', 'library lib;'); 4585 addNamedSource('/lib.dart', 'library lib;');
4952 Source source = addSource(''' 4586 Source source = addSource('''
4953 import 'lib.dart' as p; 4587 import 'lib.dart' as p;
4954 f() { 4588 f() {
4955 p = 1; 4589 p = 1;
4956 } 4590 }
4957 '''); 4591 ''');
4958 computeLibrarySourceErrors(source);
4959 assertErrors( 4592 assertErrors(
4960 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4593 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
4961 verify([source]); 4594 verify([source]);
4962 } 4595 }
4963 4596
4964 void test_prefix_conditionalPropertyAccess_call() { 4597 void test_prefix_conditionalPropertyAccess_call() {
4965 addNamedSource( 4598 addNamedSource(
4966 '/lib.dart', 4599 '/lib.dart',
4967 ''' 4600 '''
4968 library lib; 4601 library lib;
4969 g() {} 4602 g() {}
4970 '''); 4603 ''');
4971 Source source = addSource(''' 4604 Source source = addSource('''
4972 import 'lib.dart' as p; 4605 import 'lib.dart' as p;
4973 f() { 4606 f() {
4974 p?.g(); 4607 p?.g();
4975 } 4608 }
4976 '''); 4609 ''');
4977 computeLibrarySourceErrors(source);
4978 assertErrors( 4610 assertErrors(
4979 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4611 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
4980 verify([source]); 4612 verify([source]);
4981 } 4613 }
4982 4614
4983 void test_prefix_conditionalPropertyAccess_call_loadLibrary() { 4615 void test_prefix_conditionalPropertyAccess_call_loadLibrary() {
4984 addNamedSource( 4616 addNamedSource(
4985 '/lib.dart', 4617 '/lib.dart',
4986 ''' 4618 '''
4987 library lib; 4619 library lib;
4988 '''); 4620 ''');
4989 Source source = addSource(''' 4621 Source source = addSource('''
4990 import 'lib.dart' deferred as p; 4622 import 'lib.dart' deferred as p;
4991 f() { 4623 f() {
4992 p?.loadLibrary(); 4624 p?.loadLibrary();
4993 } 4625 }
4994 '''); 4626 ''');
4995 computeLibrarySourceErrors(source);
4996 assertErrors( 4627 assertErrors(
4997 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4628 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
4998 verify([source]); 4629 verify([source]);
4999 } 4630 }
5000 4631
5001 void test_prefix_conditionalPropertyAccess_get() { 4632 void test_prefix_conditionalPropertyAccess_get() {
5002 addNamedSource( 4633 addNamedSource(
5003 '/lib.dart', 4634 '/lib.dart',
5004 ''' 4635 '''
5005 library lib; 4636 library lib;
5006 var x; 4637 var x;
5007 '''); 4638 ''');
5008 Source source = addSource(''' 4639 Source source = addSource('''
5009 import 'lib.dart' as p; 4640 import 'lib.dart' as p;
5010 f() { 4641 f() {
5011 return p?.x; 4642 return p?.x;
5012 } 4643 }
5013 '''); 4644 ''');
5014 computeLibrarySourceErrors(source);
5015 assertErrors( 4645 assertErrors(
5016 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4646 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
5017 verify([source]); 4647 verify([source]);
5018 } 4648 }
5019 4649
5020 void test_prefix_conditionalPropertyAccess_get_loadLibrary() { 4650 void test_prefix_conditionalPropertyAccess_get_loadLibrary() {
5021 addNamedSource( 4651 addNamedSource(
5022 '/lib.dart', 4652 '/lib.dart',
5023 ''' 4653 '''
5024 library lib; 4654 library lib;
5025 '''); 4655 ''');
5026 Source source = addSource(''' 4656 Source source = addSource('''
5027 import 'lib.dart' deferred as p; 4657 import 'lib.dart' deferred as p;
5028 f() { 4658 f() {
5029 return p?.loadLibrary; 4659 return p?.loadLibrary;
5030 } 4660 }
5031 '''); 4661 ''');
5032 computeLibrarySourceErrors(source);
5033 assertErrors( 4662 assertErrors(
5034 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4663 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
5035 verify([source]); 4664 verify([source]);
5036 } 4665 }
5037 4666
5038 void test_prefix_conditionalPropertyAccess_set() { 4667 void test_prefix_conditionalPropertyAccess_set() {
5039 addNamedSource( 4668 addNamedSource(
5040 '/lib.dart', 4669 '/lib.dart',
5041 ''' 4670 '''
5042 library lib; 4671 library lib;
5043 var x; 4672 var x;
5044 '''); 4673 ''');
5045 Source source = addSource(''' 4674 Source source = addSource('''
5046 import 'lib.dart' as p; 4675 import 'lib.dart' as p;
5047 f() { 4676 f() {
5048 p?.x = null; 4677 p?.x = null;
5049 } 4678 }
5050 '''); 4679 ''');
5051 computeLibrarySourceErrors(source);
5052 assertErrors( 4680 assertErrors(
5053 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4681 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
5054 verify([source]); 4682 verify([source]);
5055 } 4683 }
5056 4684
5057 void test_prefix_conditionalPropertyAccess_set_loadLibrary() { 4685 void test_prefix_conditionalPropertyAccess_set_loadLibrary() {
5058 addNamedSource( 4686 addNamedSource(
5059 '/lib.dart', 4687 '/lib.dart',
5060 ''' 4688 '''
5061 library lib; 4689 library lib;
5062 '''); 4690 ''');
5063 Source source = addSource(''' 4691 Source source = addSource('''
5064 import 'lib.dart' deferred as p; 4692 import 'lib.dart' deferred as p;
5065 f() { 4693 f() {
5066 p?.loadLibrary = null; 4694 p?.loadLibrary = null;
5067 } 4695 }
5068 '''); 4696 ''');
5069 computeLibrarySourceErrors(source);
5070 assertErrors( 4697 assertErrors(
5071 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4698 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
5072 verify([source]); 4699 verify([source]);
5073 } 4700 }
5074 4701
5075 void test_prefix_unqualified_invocation_in_method() { 4702 void test_prefix_unqualified_invocation_in_method() {
5076 addNamedSource('/lib.dart', 'librarylib;'); 4703 addNamedSource('/lib.dart', 'librarylib;');
5077 Source source = addSource(''' 4704 Source source = addSource('''
5078 import 'lib.dart' as p; 4705 import 'lib.dart' as p;
5079 class C { 4706 class C {
5080 f() { 4707 f() {
5081 p(); 4708 p();
5082 } 4709 }
5083 } 4710 }
5084 '''); 4711 ''');
5085 computeLibrarySourceErrors(source);
5086 assertErrors( 4712 assertErrors(
5087 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4713 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
5088 verify([source]); 4714 verify([source]);
5089 } 4715 }
5090 4716
5091 void test_prefix_unqualified_invocation_not_in_method() { 4717 void test_prefix_unqualified_invocation_not_in_method() {
5092 addNamedSource('/lib.dart', 'librarylib;'); 4718 addNamedSource('/lib.dart', 'librarylib;');
5093 Source source = addSource(''' 4719 Source source = addSource('''
5094 import 'lib.dart' as p; 4720 import 'lib.dart' as p;
5095 f() { 4721 f() {
5096 p(); 4722 p();
5097 } 4723 }
5098 '''); 4724 ''');
5099 computeLibrarySourceErrors(source);
5100 assertErrors( 4725 assertErrors(
5101 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4726 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
5102 verify([source]); 4727 verify([source]);
5103 } 4728 }
5104 4729
5105 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() { 4730 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() {
5106 addNamedSource( 4731 addNamedSource(
5107 "/lib.dart", 4732 "/lib.dart",
5108 r''' 4733 r'''
5109 library lib; 4734 library lib;
5110 class A{}'''); 4735 class A{}''');
5111 Source source = addSource(r''' 4736 Source source = addSource(r'''
5112 import 'lib.dart' as p; 4737 import 'lib.dart' as p;
5113 typedef p(); 4738 typedef p();
5114 p.A a;'''); 4739 p.A a;''');
5115 computeLibrarySourceErrors(source);
5116 assertErrors( 4740 assertErrors(
5117 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); 4741 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]);
5118 verify([source]); 4742 verify([source]);
5119 } 4743 }
5120 4744
5121 void test_prefixCollidesWithTopLevelMembers_topLevelFunction() { 4745 void test_prefixCollidesWithTopLevelMembers_topLevelFunction() {
5122 addNamedSource( 4746 addNamedSource(
5123 "/lib.dart", 4747 "/lib.dart",
5124 r''' 4748 r'''
5125 library lib; 4749 library lib;
5126 class A{}'''); 4750 class A{}''');
5127 Source source = addSource(r''' 4751 Source source = addSource(r'''
5128 import 'lib.dart' as p; 4752 import 'lib.dart' as p;
5129 p() {} 4753 p() {}
5130 p.A a;'''); 4754 p.A a;''');
5131 computeLibrarySourceErrors(source);
5132 assertErrors( 4755 assertErrors(
5133 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); 4756 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]);
5134 verify([source]); 4757 verify([source]);
5135 } 4758 }
5136 4759
5137 void test_prefixCollidesWithTopLevelMembers_topLevelVariable() { 4760 void test_prefixCollidesWithTopLevelMembers_topLevelVariable() {
5138 addNamedSource( 4761 addNamedSource(
5139 "/lib.dart", 4762 "/lib.dart",
5140 r''' 4763 r'''
5141 library lib; 4764 library lib;
5142 class A{}'''); 4765 class A{}''');
5143 Source source = addSource(r''' 4766 Source source = addSource(r'''
5144 import 'lib.dart' as p; 4767 import 'lib.dart' as p;
5145 var p = null; 4768 var p = null;
5146 p.A a;'''); 4769 p.A a;''');
5147 computeLibrarySourceErrors(source);
5148 assertErrors( 4770 assertErrors(
5149 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); 4771 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]);
5150 verify([source]); 4772 verify([source]);
5151 } 4773 }
5152 4774
5153 void test_prefixCollidesWithTopLevelMembers_type() { 4775 void test_prefixCollidesWithTopLevelMembers_type() {
5154 addNamedSource( 4776 addNamedSource(
5155 "/lib.dart", 4777 "/lib.dart",
5156 r''' 4778 r'''
5157 library lib; 4779 library lib;
5158 class A{}'''); 4780 class A{}''');
5159 Source source = addSource(r''' 4781 Source source = addSource(r'''
5160 import 'lib.dart' as p; 4782 import 'lib.dart' as p;
5161 class p {} 4783 class p {}
5162 p.A a;'''); 4784 p.A a;''');
5163 computeLibrarySourceErrors(source);
5164 assertErrors( 4785 assertErrors(
5165 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); 4786 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]);
5166 verify([source]); 4787 verify([source]);
5167 } 4788 }
5168 4789
5169 void test_prefixNotFollowedByDot() { 4790 void test_prefixNotFollowedByDot() {
5170 addNamedSource('/lib.dart', 'library lib;'); 4791 addNamedSource('/lib.dart', 'library lib;');
5171 Source source = addSource(''' 4792 Source source = addSource('''
5172 import 'lib.dart' as p; 4793 import 'lib.dart' as p;
5173 f() { 4794 f() {
5174 return p; 4795 return p;
5175 } 4796 }
5176 '''); 4797 ''');
5177 computeLibrarySourceErrors(source);
5178 assertErrors( 4798 assertErrors(
5179 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4799 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
5180 verify([source]); 4800 verify([source]);
5181 } 4801 }
5182 4802
5183 void test_prefixNotFollowedByDot_compoundAssignment() { 4803 void test_prefixNotFollowedByDot_compoundAssignment() {
5184 addNamedSource('/lib.dart', 'library lib;'); 4804 addNamedSource('/lib.dart', 'library lib;');
5185 Source source = addSource(''' 4805 Source source = addSource('''
5186 import 'lib.dart' as p; 4806 import 'lib.dart' as p;
5187 f() { 4807 f() {
5188 p += 1; 4808 p += 1;
5189 } 4809 }
5190 '''); 4810 ''');
5191 computeLibrarySourceErrors(source);
5192 assertErrors( 4811 assertErrors(
5193 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4812 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
5194 verify([source]); 4813 verify([source]);
5195 } 4814 }
5196 4815
5197 void test_prefixNotFollowedByDot_conditionalMethodInvocation() { 4816 void test_prefixNotFollowedByDot_conditionalMethodInvocation() {
5198 addNamedSource( 4817 addNamedSource(
5199 '/lib.dart', 4818 '/lib.dart',
5200 ''' 4819 '''
5201 library lib; 4820 library lib;
5202 g() {} 4821 g() {}
5203 '''); 4822 ''');
5204 Source source = addSource(''' 4823 Source source = addSource('''
5205 import 'lib.dart' as p; 4824 import 'lib.dart' as p;
5206 f() { 4825 f() {
5207 p?.g(); 4826 p?.g();
5208 } 4827 }
5209 '''); 4828 ''');
5210 computeLibrarySourceErrors(source);
5211 assertErrors( 4829 assertErrors(
5212 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); 4830 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]);
5213 verify([source]); 4831 verify([source]);
5214 } 4832 }
5215 4833
5216 void test_privateOptionalParameter() { 4834 void test_privateOptionalParameter() {
5217 Source source = addSource("f({var _p}) {}"); 4835 Source source = addSource("f({var _p}) {}");
5218 computeLibrarySourceErrors(source);
5219 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); 4836 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]);
5220 verify([source]); 4837 verify([source]);
5221 } 4838 }
5222 4839
5223 void test_privateOptionalParameter_fieldFormal() { 4840 void test_privateOptionalParameter_fieldFormal() {
5224 Source source = addSource(r''' 4841 Source source = addSource(r'''
5225 class A { 4842 class A {
5226 var _p; 4843 var _p;
5227 A({this._p: 0}); 4844 A({this._p: 0});
5228 }'''); 4845 }''');
5229 computeLibrarySourceErrors(source);
5230 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); 4846 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]);
5231 verify([source]); 4847 verify([source]);
5232 } 4848 }
5233 4849
5234 void test_privateOptionalParameter_withDefaultValue() { 4850 void test_privateOptionalParameter_withDefaultValue() {
5235 Source source = addSource("f({_p : 0}) {}"); 4851 Source source = addSource("f({_p : 0}) {}");
5236 computeLibrarySourceErrors(source);
5237 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); 4852 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]);
5238 verify([source]); 4853 verify([source]);
5239 } 4854 }
5240 4855
5241 void test_recursiveCompileTimeConstant() { 4856 void test_recursiveCompileTimeConstant() {
5242 Source source = addSource(r''' 4857 Source source = addSource(r'''
5243 class A { 4858 class A {
5244 const A(); 4859 const A();
5245 final m = const A(); 4860 final m = const A();
5246 }'''); 4861 }''');
5247 computeLibrarySourceErrors(source);
5248 assertErrors( 4862 assertErrors(
5249 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); 4863 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]);
5250 verify([source]); 4864 verify([source]);
5251 } 4865 }
5252 4866
5253 void test_recursiveCompileTimeConstant_cycle() { 4867 void test_recursiveCompileTimeConstant_cycle() {
5254 Source source = addSource(r''' 4868 Source source = addSource(r'''
5255 const x = y + 1; 4869 const x = y + 1;
5256 const y = x + 1;'''); 4870 const y = x + 1;''');
5257 computeLibrarySourceErrors(source);
5258 assertErrors(source, [ 4871 assertErrors(source, [
5259 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, 4872 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT,
5260 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT 4873 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT
5261 ]); 4874 ]);
5262 verify([source]); 4875 verify([source]);
5263 } 4876 }
5264 4877
5265 void test_recursiveCompileTimeConstant_initializer_after_toplevel_var() { 4878 void test_recursiveCompileTimeConstant_initializer_after_toplevel_var() {
5266 Source source = addSource(''' 4879 Source source = addSource('''
5267 const y = const C(); 4880 const y = const C();
5268 class C { 4881 class C {
5269 const C() : x = y; 4882 const C() : x = y;
5270 final x; 4883 final x;
5271 } 4884 }
5272 '''); 4885 ''');
5273 computeLibrarySourceErrors(source);
5274 assertErrors( 4886 assertErrors(
5275 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); 4887 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]);
5276 verify([source]); 4888 verify([source]);
5277 } 4889 }
5278 4890
5279 void test_recursiveCompileTimeConstant_singleVariable() { 4891 void test_recursiveCompileTimeConstant_singleVariable() {
5280 Source source = addSource(r''' 4892 Source source = addSource(r'''
5281 const x = x; 4893 const x = x;
5282 '''); 4894 ''');
5283 computeLibrarySourceErrors(source);
5284 assertErrors( 4895 assertErrors(
5285 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); 4896 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]);
5286 verify([source]); 4897 verify([source]);
5287 } 4898 }
5288 4899
5289 void test_recursiveConstructorRedirect() { 4900 void test_recursiveConstructorRedirect() {
5290 Source source = addSource(r''' 4901 Source source = addSource(r'''
5291 class A { 4902 class A {
5292 A.a() : this.b(); 4903 A.a() : this.b();
5293 A.b() : this.a(); 4904 A.b() : this.a();
5294 }'''); 4905 }''');
5295 computeLibrarySourceErrors(source);
5296 assertErrors(source, [ 4906 assertErrors(source, [
5297 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT, 4907 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT,
5298 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT 4908 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT
5299 ]); 4909 ]);
5300 verify([source]); 4910 verify([source]);
5301 } 4911 }
5302 4912
5303 void test_recursiveConstructorRedirect_directSelfReference() { 4913 void test_recursiveConstructorRedirect_directSelfReference() {
5304 Source source = addSource(r''' 4914 Source source = addSource(r'''
5305 class A { 4915 class A {
5306 A() : this(); 4916 A() : this();
5307 }'''); 4917 }''');
5308 computeLibrarySourceErrors(source);
5309 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]); 4918 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]);
5310 verify([source]); 4919 verify([source]);
5311 } 4920 }
5312 4921
5313 void test_recursiveFactoryRedirect() { 4922 void test_recursiveFactoryRedirect() {
5314 Source source = addSource(r''' 4923 Source source = addSource(r'''
5315 class A implements B { 4924 class A implements B {
5316 factory A() = C; 4925 factory A() = C;
5317 } 4926 }
5318 class B implements C { 4927 class B implements C {
5319 factory B() = A; 4928 factory B() = A;
5320 } 4929 }
5321 class C implements A { 4930 class C implements A {
5322 factory C() = B; 4931 factory C() = B;
5323 }'''); 4932 }''');
5324 computeLibrarySourceErrors(source);
5325 assertErrors(source, [ 4933 assertErrors(source, [
5326 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 4934 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5327 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 4935 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5328 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 4936 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5329 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 4937 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5330 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 4938 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5331 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 4939 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5332 ]); 4940 ]);
5333 verify([source]); 4941 verify([source]);
5334 } 4942 }
5335 4943
5336 void test_recursiveFactoryRedirect_directSelfReference() { 4944 void test_recursiveFactoryRedirect_directSelfReference() {
5337 Source source = addSource(r''' 4945 Source source = addSource(r'''
5338 class A { 4946 class A {
5339 factory A() = A; 4947 factory A() = A;
5340 }'''); 4948 }''');
5341 computeLibrarySourceErrors(source);
5342 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); 4949 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]);
5343 verify([source]); 4950 verify([source]);
5344 } 4951 }
5345 4952
5346 void test_recursiveFactoryRedirect_diverging() { 4953 void test_recursiveFactoryRedirect_diverging() {
5347 // Analysis should terminate even though the redirections don't reach a 4954 // Analysis should terminate even though the redirections don't reach a
5348 // fixed point. (C<int> redirects to C<C<int>>, then to C<C<C<int>>>, and 4955 // fixed point. (C<int> redirects to C<C<int>>, then to C<C<C<int>>>, and
5349 // so on). 4956 // so on).
5350 Source source = addSource(''' 4957 Source source = addSource('''
5351 class C<T> { 4958 class C<T> {
5352 const factory C() = C<C<T>>; 4959 const factory C() = C<C<T>>;
5353 } 4960 }
5354 main() { 4961 main() {
5355 const C<int>(); 4962 const C<int>();
5356 } 4963 }
5357 '''); 4964 ''');
5358 computeLibrarySourceErrors(source);
5359 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); 4965 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]);
5360 verify([source]); 4966 verify([source]);
5361 } 4967 }
5362 4968
5363 void test_recursiveFactoryRedirect_generic() { 4969 void test_recursiveFactoryRedirect_generic() {
5364 Source source = addSource(r''' 4970 Source source = addSource(r'''
5365 class A<T> implements B<T> { 4971 class A<T> implements B<T> {
5366 factory A() = C; 4972 factory A() = C;
5367 } 4973 }
5368 class B<T> implements C<T> { 4974 class B<T> implements C<T> {
5369 factory B() = A; 4975 factory B() = A;
5370 } 4976 }
5371 class C<T> implements A<T> { 4977 class C<T> implements A<T> {
5372 factory C() = B; 4978 factory C() = B;
5373 }'''); 4979 }''');
5374 computeLibrarySourceErrors(source);
5375 assertErrors(source, [ 4980 assertErrors(source, [
5376 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 4981 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5377 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 4982 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5378 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 4983 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5379 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 4984 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5380 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 4985 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5381 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 4986 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5382 ]); 4987 ]);
5383 verify([source]); 4988 verify([source]);
5384 } 4989 }
5385 4990
5386 void test_recursiveFactoryRedirect_named() { 4991 void test_recursiveFactoryRedirect_named() {
5387 Source source = addSource(r''' 4992 Source source = addSource(r'''
5388 class A implements B { 4993 class A implements B {
5389 factory A.nameA() = C.nameC; 4994 factory A.nameA() = C.nameC;
5390 } 4995 }
5391 class B implements C { 4996 class B implements C {
5392 factory B.nameB() = A.nameA; 4997 factory B.nameB() = A.nameA;
5393 } 4998 }
5394 class C implements A { 4999 class C implements A {
5395 factory C.nameC() = B.nameB; 5000 factory C.nameC() = B.nameB;
5396 }'''); 5001 }''');
5397 computeLibrarySourceErrors(source);
5398 assertErrors(source, [ 5002 assertErrors(source, [
5399 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 5003 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5400 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 5004 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5401 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 5005 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5402 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5006 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5403 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5007 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5404 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 5008 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5405 ]); 5009 ]);
5406 verify([source]); 5010 verify([source]);
5407 } 5011 }
5408 5012
5409 /** 5013 /**
5410 * "A" references "C" which has cycle with "B". But we should not report probl em for "A" - it is 5014 * "A" references "C" which has cycle with "B". But we should not report probl em for "A" - it is
5411 * not the part of a cycle. 5015 * not the part of a cycle.
5412 */ 5016 */
5413 void test_recursiveFactoryRedirect_outsideCycle() { 5017 void test_recursiveFactoryRedirect_outsideCycle() {
5414 Source source = addSource(r''' 5018 Source source = addSource(r'''
5415 class A { 5019 class A {
5416 factory A() = C; 5020 factory A() = C;
5417 } 5021 }
5418 class B implements C { 5022 class B implements C {
5419 factory B() = C; 5023 factory B() = C;
5420 } 5024 }
5421 class C implements A, B { 5025 class C implements A, B {
5422 factory C() = B; 5026 factory C() = B;
5423 }'''); 5027 }''');
5424 computeLibrarySourceErrors(source);
5425 assertErrors(source, [ 5028 assertErrors(source, [
5426 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 5029 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5427 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, 5030 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
5428 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5031 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5429 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 5032 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5430 ]); 5033 ]);
5431 verify([source]); 5034 verify([source]);
5432 } 5035 }
5433 5036
5434 void test_recursiveInterfaceInheritance_extends() { 5037 void test_recursiveInterfaceInheritance_extends() {
5435 Source source = addSource(r''' 5038 Source source = addSource(r'''
5436 class A extends B {} 5039 class A extends B {}
5437 class B extends A {}'''); 5040 class B extends A {}''');
5438 computeLibrarySourceErrors(source);
5439 assertErrors(source, [ 5041 assertErrors(source, [
5440 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5042 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5441 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 5043 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5442 ]); 5044 ]);
5443 verify([source]); 5045 verify([source]);
5444 } 5046 }
5445 5047
5446 void test_recursiveInterfaceInheritance_extends_implements() { 5048 void test_recursiveInterfaceInheritance_extends_implements() {
5447 Source source = addSource(r''' 5049 Source source = addSource(r'''
5448 class A extends B {} 5050 class A extends B {}
5449 class B implements A {}'''); 5051 class B implements A {}''');
5450 computeLibrarySourceErrors(source);
5451 assertErrors(source, [ 5052 assertErrors(source, [
5452 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5053 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5453 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 5054 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5454 ]); 5055 ]);
5455 verify([source]); 5056 verify([source]);
5456 } 5057 }
5457 5058
5458 void test_recursiveInterfaceInheritance_implements() { 5059 void test_recursiveInterfaceInheritance_implements() {
5459 Source source = addSource(r''' 5060 Source source = addSource(r'''
5460 class A implements B {} 5061 class A implements B {}
5461 class B implements A {}'''); 5062 class B implements A {}''');
5462 computeLibrarySourceErrors(source);
5463 assertErrors(source, [ 5063 assertErrors(source, [
5464 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5064 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5465 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 5065 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5466 ]); 5066 ]);
5467 verify([source]); 5067 verify([source]);
5468 } 5068 }
5469 5069
5470 void test_recursiveInterfaceInheritance_mixin() { 5070 void test_recursiveInterfaceInheritance_mixin() {
5471 Source source = addSource(r''' 5071 Source source = addSource(r'''
5472 class M1 = Object with M2; 5072 class M1 = Object with M2;
5473 class M2 = Object with M1;'''); 5073 class M2 = Object with M1;''');
5474 computeLibrarySourceErrors(source);
5475 assertErrors(source, [ 5074 assertErrors(source, [
5476 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5075 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5477 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 5076 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5478 ]); 5077 ]);
5479 verify([source]); 5078 verify([source]);
5480 } 5079 }
5481 5080
5482 void test_recursiveInterfaceInheritance_mixin_superclass() { 5081 void test_recursiveInterfaceInheritance_mixin_superclass() {
5483 // Make sure we don't get CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS in 5082 // Make sure we don't get CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS in
5484 // addition--that would just be confusing. 5083 // addition--that would just be confusing.
5485 Source source = addSource(''' 5084 Source source = addSource('''
5486 class C = D with M; 5085 class C = D with M;
5487 class D = C with M; 5086 class D = C with M;
5488 class M {} 5087 class M {}
5489 '''); 5088 ''');
5490 computeLibrarySourceErrors(source);
5491 assertErrors(source, [ 5089 assertErrors(source, [
5492 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5090 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5493 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 5091 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5494 ]); 5092 ]);
5495 verify([source]); 5093 verify([source]);
5496 } 5094 }
5497 5095
5498 void test_recursiveInterfaceInheritance_tail() { 5096 void test_recursiveInterfaceInheritance_tail() {
5499 Source source = addSource(r''' 5097 Source source = addSource(r'''
5500 abstract class A implements A {} 5098 abstract class A implements A {}
5501 class B implements A {}'''); 5099 class B implements A {}''');
5502 computeLibrarySourceErrors(source);
5503 assertErrors(source, [ 5100 assertErrors(source, [
5504 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS 5101 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS
5505 ]); 5102 ]);
5506 verify([source]); 5103 verify([source]);
5507 } 5104 }
5508 5105
5509 void test_recursiveInterfaceInheritance_tail2() { 5106 void test_recursiveInterfaceInheritance_tail2() {
5510 Source source = addSource(r''' 5107 Source source = addSource(r'''
5511 abstract class A implements B {} 5108 abstract class A implements B {}
5512 abstract class B implements A {} 5109 abstract class B implements A {}
5513 class C implements A {}'''); 5110 class C implements A {}''');
5514 computeLibrarySourceErrors(source);
5515 assertErrors(source, [ 5111 assertErrors(source, [
5516 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5112 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5517 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 5113 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5518 ]); 5114 ]);
5519 verify([source]); 5115 verify([source]);
5520 } 5116 }
5521 5117
5522 void test_recursiveInterfaceInheritance_tail3() { 5118 void test_recursiveInterfaceInheritance_tail3() {
5523 Source source = addSource(r''' 5119 Source source = addSource(r'''
5524 abstract class A implements B {} 5120 abstract class A implements B {}
5525 abstract class B implements C {} 5121 abstract class B implements C {}
5526 abstract class C implements A {} 5122 abstract class C implements A {}
5527 class D implements A {}'''); 5123 class D implements A {}''');
5528 computeLibrarySourceErrors(source);
5529 assertErrors(source, [ 5124 assertErrors(source, [
5530 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5125 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5531 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5126 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5532 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE 5127 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE
5533 ]); 5128 ]);
5534 verify([source]); 5129 verify([source]);
5535 } 5130 }
5536 5131
5537 void test_recursiveInterfaceInheritanceBaseCaseExtends() { 5132 void test_recursiveInterfaceInheritanceBaseCaseExtends() {
5538 Source source = addSource("class A extends A {}"); 5133 Source source = addSource("class A extends A {}");
5539 computeLibrarySourceErrors(source);
5540 assertErrors(source, [ 5134 assertErrors(source, [
5541 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS 5135 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS
5542 ]); 5136 ]);
5543 verify([source]); 5137 verify([source]);
5544 } 5138 }
5545 5139
5546 void test_recursiveInterfaceInheritanceBaseCaseExtends_abstract() { 5140 void test_recursiveInterfaceInheritanceBaseCaseExtends_abstract() {
5547 Source source = addSource(r''' 5141 Source source = addSource(r'''
5548 class C extends C { 5142 class C extends C {
5549 var bar = 0; 5143 var bar = 0;
5550 m(); 5144 m();
5551 } 5145 }
5552 '''); 5146 ''');
5553 computeLibrarySourceErrors(source);
5554 assertErrors(source, [ 5147 assertErrors(source, [
5555 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS, 5148 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS,
5556 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, 5149 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER,
5557 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE 5150 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE
5558 ]); 5151 ]);
5559 verify([source]); 5152 verify([source]);
5560 } 5153 }
5561 5154
5562 void test_recursiveInterfaceInheritanceBaseCaseImplements() { 5155 void test_recursiveInterfaceInheritanceBaseCaseImplements() {
5563 Source source = addSource("class A implements A {}"); 5156 Source source = addSource("class A implements A {}");
5564 computeLibrarySourceErrors(source);
5565 assertErrors(source, [ 5157 assertErrors(source, [
5566 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS 5158 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS
5567 ]); 5159 ]);
5568 verify([source]); 5160 verify([source]);
5569 } 5161 }
5570 5162
5571 void test_recursiveInterfaceInheritanceBaseCaseImplements_typeAlias() { 5163 void test_recursiveInterfaceInheritanceBaseCaseImplements_typeAlias() {
5572 Source source = addSource(r''' 5164 Source source = addSource(r'''
5573 class A {} 5165 class A {}
5574 class M {} 5166 class M {}
5575 class B = A with M implements B;'''); 5167 class B = A with M implements B;''');
5576 computeLibrarySourceErrors(source);
5577 assertErrors(source, [ 5168 assertErrors(source, [
5578 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS 5169 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS
5579 ]); 5170 ]);
5580 verify([source]); 5171 verify([source]);
5581 } 5172 }
5582 5173
5583 void test_recursiveInterfaceInheritanceBaseCaseWith() { 5174 void test_recursiveInterfaceInheritanceBaseCaseWith() {
5584 Source source = addSource("class M = Object with M;"); 5175 Source source = addSource("class M = Object with M;");
5585 computeLibrarySourceErrors(source);
5586 assertErrors(source, 5176 assertErrors(source,
5587 [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH]); 5177 [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH]);
5588 verify([source]); 5178 verify([source]);
5589 } 5179 }
5590 5180
5591 void test_redirectGenerativeToMissingConstructor() { 5181 void test_redirectGenerativeToMissingConstructor() {
5592 Source source = addSource(r''' 5182 Source source = addSource(r'''
5593 class A { 5183 class A {
5594 A() : this.noSuchConstructor(); 5184 A() : this.noSuchConstructor();
5595 }'''); 5185 }''');
5596 computeLibrarySourceErrors(source);
5597 assertErrors(source, 5186 assertErrors(source,
5598 [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]); 5187 [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]);
5599 } 5188 }
5600 5189
5601 void test_redirectGenerativeToNonGenerativeConstructor() { 5190 void test_redirectGenerativeToNonGenerativeConstructor() {
5602 Source source = addSource(r''' 5191 Source source = addSource(r'''
5603 class A { 5192 class A {
5604 A() : this.x(); 5193 A() : this.x();
5605 factory A.x() => null; 5194 factory A.x() => null;
5606 }'''); 5195 }''');
5607 computeLibrarySourceErrors(source);
5608 assertErrors(source, [ 5196 assertErrors(source, [
5609 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR 5197 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR
5610 ]); 5198 ]);
5611 verify([source]); 5199 verify([source]);
5612 } 5200 }
5613 5201
5614 void test_redirectToMissingConstructor_named() { 5202 void test_redirectToMissingConstructor_named() {
5615 Source source = addSource(r''' 5203 Source source = addSource(r'''
5616 class A implements B{ 5204 class A implements B{
5617 A() {} 5205 A() {}
5618 } 5206 }
5619 class B { 5207 class B {
5620 const factory B() = A.name; 5208 const factory B() = A.name;
5621 }'''); 5209 }''');
5622 computeLibrarySourceErrors(source);
5623 assertErrors( 5210 assertErrors(
5624 source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); 5211 source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]);
5625 } 5212 }
5626 5213
5627 void test_redirectToMissingConstructor_unnamed() { 5214 void test_redirectToMissingConstructor_unnamed() {
5628 Source source = addSource(r''' 5215 Source source = addSource(r'''
5629 class A implements B{ 5216 class A implements B{
5630 A.name() {} 5217 A.name() {}
5631 } 5218 }
5632 class B { 5219 class B {
5633 const factory B() = A; 5220 const factory B() = A;
5634 }'''); 5221 }''');
5635 computeLibrarySourceErrors(source);
5636 assertErrors( 5222 assertErrors(
5637 source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); 5223 source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]);
5638 } 5224 }
5639 5225
5640 void test_redirectToNonClass_notAType() { 5226 void test_redirectToNonClass_notAType() {
5641 Source source = addSource(r''' 5227 Source source = addSource(r'''
5642 int A; 5228 int A;
5643 class B { 5229 class B {
5644 const factory B() = A; 5230 const factory B() = A;
5645 }'''); 5231 }''');
5646 computeLibrarySourceErrors(source);
5647 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); 5232 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]);
5648 verify([source]); 5233 verify([source]);
5649 } 5234 }
5650 5235
5651 void test_redirectToNonClass_undefinedIdentifier() { 5236 void test_redirectToNonClass_undefinedIdentifier() {
5652 Source source = addSource(r''' 5237 Source source = addSource(r'''
5653 class B { 5238 class B {
5654 const factory B() = A; 5239 const factory B() = A;
5655 }'''); 5240 }''');
5656 computeLibrarySourceErrors(source);
5657 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); 5241 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]);
5658 verify([source]); 5242 verify([source]);
5659 } 5243 }
5660 5244
5661 void test_redirectToNonConstConstructor() { 5245 void test_redirectToNonConstConstructor() {
5662 Source source = addSource(r''' 5246 Source source = addSource(r'''
5663 class A { 5247 class A {
5664 A.a() {} 5248 A.a() {}
5665 const factory A.b() = A.a; 5249 const factory A.b() = A.a;
5666 }'''); 5250 }''');
5667 computeLibrarySourceErrors(source);
5668 assertErrors( 5251 assertErrors(
5669 source, [CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR]); 5252 source, [CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR]);
5670 verify([source]); 5253 verify([source]);
5671 } 5254 }
5672 5255
5673 void test_referencedBeforeDeclaration_hideInBlock_function() { 5256 void test_referencedBeforeDeclaration_hideInBlock_function() {
5674 Source source = addSource(r''' 5257 Source source = addSource(r'''
5675 var v = 1; 5258 var v = 1;
5676 main() { 5259 main() {
5677 print(v); 5260 print(v);
5678 v() {} 5261 v() {}
5679 } 5262 }
5680 print(x) {}'''); 5263 print(x) {}''');
5681 computeLibrarySourceErrors(source);
5682 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 5264 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5683 } 5265 }
5684 5266
5685 void test_referencedBeforeDeclaration_hideInBlock_local() { 5267 void test_referencedBeforeDeclaration_hideInBlock_local() {
5686 Source source = addSource(r''' 5268 Source source = addSource(r'''
5687 var v = 1; 5269 var v = 1;
5688 main() { 5270 main() {
5689 print(v); 5271 print(v);
5690 var v = 2; 5272 var v = 2;
5691 } 5273 }
5692 print(x) {}'''); 5274 print(x) {}''');
5693 computeLibrarySourceErrors(source);
5694 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 5275 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5695 } 5276 }
5696 5277
5697 void test_referencedBeforeDeclaration_hideInBlock_subBlock() { 5278 void test_referencedBeforeDeclaration_hideInBlock_subBlock() {
5698 Source source = addSource(r''' 5279 Source source = addSource(r'''
5699 var v = 1; 5280 var v = 1;
5700 main() { 5281 main() {
5701 { 5282 {
5702 print(v); 5283 print(v);
5703 } 5284 }
5704 var v = 2; 5285 var v = 2;
5705 } 5286 }
5706 print(x) {}'''); 5287 print(x) {}''');
5707 computeLibrarySourceErrors(source);
5708 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 5288 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5709 } 5289 }
5710 5290
5711 void test_referencedBeforeDeclaration_inInitializer_closure() { 5291 void test_referencedBeforeDeclaration_inInitializer_closure() {
5712 Source source = addSource(r''' 5292 Source source = addSource(r'''
5713 main() { 5293 main() {
5714 var v = () => v; 5294 var v = () => v;
5715 }'''); 5295 }''');
5716 computeLibrarySourceErrors(source);
5717 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 5296 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5718 } 5297 }
5719 5298
5720 void test_referencedBeforeDeclaration_inInitializer_directly() { 5299 void test_referencedBeforeDeclaration_inInitializer_directly() {
5721 Source source = addSource(r''' 5300 Source source = addSource(r'''
5722 main() { 5301 main() {
5723 var v = v; 5302 var v = v;
5724 }'''); 5303 }''');
5725 computeLibrarySourceErrors(source);
5726 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 5304 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5727 } 5305 }
5728 5306
5729 void test_referencedBeforeDeclaration_type_localFunction() { 5307 void test_referencedBeforeDeclaration_type_localFunction() {
5730 Source source = addSource(r''' 5308 Source source = addSource(r'''
5731 void testTypeRef() { 5309 void testTypeRef() {
5732 String s = ''; 5310 String s = '';
5733 int String(int x) => x + 1; 5311 int String(int x) => x + 1;
5734 } 5312 }
5735 '''); 5313 ''');
5736 computeLibrarySourceErrors(source);
5737 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 5314 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5738 } 5315 }
5739 5316
5740 void test_referencedBeforeDeclaration_type_localVariable() { 5317 void test_referencedBeforeDeclaration_type_localVariable() {
5741 Source source = addSource(r''' 5318 Source source = addSource(r'''
5742 void testTypeRef() { 5319 void testTypeRef() {
5743 String s = ''; 5320 String s = '';
5744 var String = ''; 5321 var String = '';
5745 } 5322 }
5746 '''); 5323 ''');
5747 computeLibrarySourceErrors(source);
5748 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 5324 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5749 } 5325 }
5750 5326
5751 void test_rethrowOutsideCatch() { 5327 void test_rethrowOutsideCatch() {
5752 Source source = addSource(r''' 5328 Source source = addSource(r'''
5753 f() { 5329 f() {
5754 rethrow; 5330 rethrow;
5755 }'''); 5331 }''');
5756 computeLibrarySourceErrors(source);
5757 assertErrors(source, [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]); 5332 assertErrors(source, [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]);
5758 verify([source]); 5333 verify([source]);
5759 } 5334 }
5760 5335
5761 void test_returnInGenerativeConstructor() { 5336 void test_returnInGenerativeConstructor() {
5762 Source source = addSource(r''' 5337 Source source = addSource(r'''
5763 class A { 5338 class A {
5764 A() { return 0; } 5339 A() { return 0; }
5765 }'''); 5340 }''');
5766 computeLibrarySourceErrors(source);
5767 assertErrors( 5341 assertErrors(
5768 source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]); 5342 source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]);
5769 verify([source]); 5343 verify([source]);
5770 } 5344 }
5771 5345
5772 void test_returnInGenerativeConstructor_expressionFunctionBody() { 5346 void test_returnInGenerativeConstructor_expressionFunctionBody() {
5773 Source source = addSource(r''' 5347 Source source = addSource(r'''
5774 class A { 5348 class A {
5775 A() => null; 5349 A() => null;
5776 }'''); 5350 }''');
5777 computeLibrarySourceErrors(source);
5778 assertErrors( 5351 assertErrors(
5779 source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]); 5352 source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]);
5780 verify([source]); 5353 verify([source]);
5781 } 5354 }
5782 5355
5783 void test_returnInGenerator_asyncStar() { 5356 void test_returnInGenerator_asyncStar() {
5784 Source source = addSource(r''' 5357 Source source = addSource(r'''
5785 f() async* { 5358 f() async* {
5786 return 0; 5359 return 0;
5787 }'''); 5360 }''');
5788 computeLibrarySourceErrors(source);
5789 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); 5361 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]);
5790 verify([source]); 5362 verify([source]);
5791 } 5363 }
5792 5364
5793 void test_returnInGenerator_syncStar() { 5365 void test_returnInGenerator_syncStar() {
5794 Source source = addSource(r''' 5366 Source source = addSource(r'''
5795 f() sync* { 5367 f() sync* {
5796 return 0; 5368 return 0;
5797 }'''); 5369 }''');
5798 computeLibrarySourceErrors(source);
5799 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); 5370 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]);
5800 verify([source]); 5371 verify([source]);
5801 } 5372 }
5802 5373
5803 void test_sharedDeferredPrefix() { 5374 void test_sharedDeferredPrefix() {
5804 resolveWithErrors(<String>[ 5375 resolveWithErrors(<String>[
5805 r''' 5376 r'''
5806 library lib1; 5377 library lib1;
5807 f1() {}''', 5378 f1() {}''',
5808 r''' 5379 r'''
5809 library lib2; 5380 library lib2;
5810 f2() {}''', 5381 f2() {}''',
5811 r''' 5382 r'''
5812 library root; 5383 library root;
5813 import 'lib1.dart' deferred as lib; 5384 import 'lib1.dart' deferred as lib;
5814 import 'lib2.dart' as lib; 5385 import 'lib2.dart' as lib;
5815 main() { lib.f1(); lib.f2(); }''' 5386 main() { lib.f1(); lib.f2(); }'''
5816 ], <ErrorCode>[ 5387 ], <ErrorCode>[
5817 CompileTimeErrorCode.SHARED_DEFERRED_PREFIX 5388 CompileTimeErrorCode.SHARED_DEFERRED_PREFIX
5818 ]); 5389 ]);
5819 } 5390 }
5820 5391
5821 void test_superInInvalidContext_binaryExpression() { 5392 void test_superInInvalidContext_binaryExpression() {
5822 Source source = addSource("var v = super + 0;"); 5393 Source source = addSource("var v = super + 0;");
5823 computeLibrarySourceErrors(source);
5824 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 5394 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
5825 // no verify(), 'super.v' is not resolved 5395 // no verify(), 'super.v' is not resolved
5826 } 5396 }
5827 5397
5828 void test_superInInvalidContext_constructorFieldInitializer() { 5398 void test_superInInvalidContext_constructorFieldInitializer() {
5829 Source source = addSource(r''' 5399 Source source = addSource(r'''
5830 class A { 5400 class A {
5831 m() {} 5401 m() {}
5832 } 5402 }
5833 class B extends A { 5403 class B extends A {
5834 var f; 5404 var f;
5835 B() : f = super.m(); 5405 B() : f = super.m();
5836 }'''); 5406 }''');
5837 computeLibrarySourceErrors(source);
5838 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 5407 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
5839 // no verify(), 'super.m' is not resolved 5408 // no verify(), 'super.m' is not resolved
5840 } 5409 }
5841 5410
5842 void test_superInInvalidContext_factoryConstructor() { 5411 void test_superInInvalidContext_factoryConstructor() {
5843 Source source = addSource(r''' 5412 Source source = addSource(r'''
5844 class A { 5413 class A {
5845 m() {} 5414 m() {}
5846 } 5415 }
5847 class B extends A { 5416 class B extends A {
5848 factory B() { 5417 factory B() {
5849 super.m(); 5418 super.m();
5850 return null; 5419 return null;
5851 } 5420 }
5852 }'''); 5421 }''');
5853 computeLibrarySourceErrors(source);
5854 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 5422 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
5855 // no verify(), 'super.m' is not resolved 5423 // no verify(), 'super.m' is not resolved
5856 } 5424 }
5857 5425
5858 void test_superInInvalidContext_instanceVariableInitializer() { 5426 void test_superInInvalidContext_instanceVariableInitializer() {
5859 Source source = addSource(r''' 5427 Source source = addSource(r'''
5860 class A { 5428 class A {
5861 var a; 5429 var a;
5862 } 5430 }
5863 class B extends A { 5431 class B extends A {
5864 var b = super.a; 5432 var b = super.a;
5865 }'''); 5433 }''');
5866 computeLibrarySourceErrors(source);
5867 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 5434 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
5868 // no verify(), 'super.a' is not resolved 5435 // no verify(), 'super.a' is not resolved
5869 } 5436 }
5870 5437
5871 void test_superInInvalidContext_staticMethod() { 5438 void test_superInInvalidContext_staticMethod() {
5872 Source source = addSource(r''' 5439 Source source = addSource(r'''
5873 class A { 5440 class A {
5874 static m() {} 5441 static m() {}
5875 } 5442 }
5876 class B extends A { 5443 class B extends A {
5877 static n() { return super.m(); } 5444 static n() { return super.m(); }
5878 }'''); 5445 }''');
5879 computeLibrarySourceErrors(source);
5880 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 5446 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
5881 // no verify(), 'super.m' is not resolved 5447 // no verify(), 'super.m' is not resolved
5882 } 5448 }
5883 5449
5884 void test_superInInvalidContext_staticVariableInitializer() { 5450 void test_superInInvalidContext_staticVariableInitializer() {
5885 Source source = addSource(r''' 5451 Source source = addSource(r'''
5886 class A { 5452 class A {
5887 static int a = 0; 5453 static int a = 0;
5888 } 5454 }
5889 class B extends A { 5455 class B extends A {
5890 static int b = super.a; 5456 static int b = super.a;
5891 }'''); 5457 }''');
5892 computeLibrarySourceErrors(source);
5893 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 5458 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
5894 // no verify(), 'super.a' is not resolved 5459 // no verify(), 'super.a' is not resolved
5895 } 5460 }
5896 5461
5897 void test_superInInvalidContext_topLevelFunction() { 5462 void test_superInInvalidContext_topLevelFunction() {
5898 Source source = addSource(r''' 5463 Source source = addSource(r'''
5899 f() { 5464 f() {
5900 super.f(); 5465 super.f();
5901 }'''); 5466 }''');
5902 computeLibrarySourceErrors(source);
5903 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 5467 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
5904 // no verify(), 'super.f' is not resolved 5468 // no verify(), 'super.f' is not resolved
5905 } 5469 }
5906 5470
5907 void test_superInInvalidContext_topLevelVariableInitializer() { 5471 void test_superInInvalidContext_topLevelVariableInitializer() {
5908 Source source = addSource("var v = super.y;"); 5472 Source source = addSource("var v = super.y;");
5909 computeLibrarySourceErrors(source);
5910 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 5473 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
5911 // no verify(), 'super.y' is not resolved 5474 // no verify(), 'super.y' is not resolved
5912 } 5475 }
5913 5476
5914 void test_superInRedirectingConstructor_redirectionSuper() { 5477 void test_superInRedirectingConstructor_redirectionSuper() {
5915 Source source = addSource(r''' 5478 Source source = addSource(r'''
5916 class A {} 5479 class A {}
5917 class B { 5480 class B {
5918 B() : this.name(), super(); 5481 B() : this.name(), super();
5919 B.name() {} 5482 B.name() {}
5920 }'''); 5483 }''');
5921 computeLibrarySourceErrors(source);
5922 assertErrors( 5484 assertErrors(
5923 source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]); 5485 source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]);
5924 verify([source]); 5486 verify([source]);
5925 } 5487 }
5926 5488
5927 void test_superInRedirectingConstructor_superRedirection() { 5489 void test_superInRedirectingConstructor_superRedirection() {
5928 Source source = addSource(r''' 5490 Source source = addSource(r'''
5929 class A {} 5491 class A {}
5930 class B { 5492 class B {
5931 B() : super(), this.name(); 5493 B() : super(), this.name();
5932 B.name() {} 5494 B.name() {}
5933 }'''); 5495 }''');
5934 computeLibrarySourceErrors(source);
5935 assertErrors( 5496 assertErrors(
5936 source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]); 5497 source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]);
5937 verify([source]); 5498 verify([source]);
5938 } 5499 }
5939 5500
5940 void test_symbol_constructor_badArgs() { 5501 void test_symbol_constructor_badArgs() {
5941 Source source = addSource(r''' 5502 Source source = addSource(r'''
5942 var s1 = const Symbol('3'); 5503 var s1 = const Symbol('3');
5943 var s2 = const Symbol(3); 5504 var s2 = const Symbol(3);
5944 var s3 = const Symbol(); 5505 var s3 = const Symbol();
5945 var s4 = const Symbol('x', 'y'); 5506 var s4 = const Symbol('x', 'y');
5946 var s5 = const Symbol('x', foo: 'x');'''); 5507 var s5 = const Symbol('x', foo: 'x');''');
5947 computeLibrarySourceErrors(source);
5948 assertErrors(source, [ 5508 assertErrors(source, [
5949 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 5509 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
5950 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 5510 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
5951 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 5511 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
5952 CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS, 5512 CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS,
5953 CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 5513 CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS,
5954 CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER 5514 CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER
5955 ]); 5515 ]);
5956 verify([source]); 5516 verify([source]);
5957 } 5517 }
5958 5518
5959 void test_typeAliasCannotReferenceItself_11987() { 5519 void test_typeAliasCannotReferenceItself_11987() {
5960 Source source = addSource(r''' 5520 Source source = addSource(r'''
5961 typedef void F(List<G> l); 5521 typedef void F(List<G> l);
5962 typedef void G(List<F> l); 5522 typedef void G(List<F> l);
5963 main() { 5523 main() {
5964 F foo(G g) => g; 5524 F foo(G g) => g;
5965 }'''); 5525 }''');
5966 computeLibrarySourceErrors(source);
5967 assertErrors(source, [ 5526 assertErrors(source, [
5968 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 5527 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF,
5969 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF 5528 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF
5970 ]); 5529 ]);
5971 verify([source]); 5530 verify([source]);
5972 } 5531 }
5973 5532
5974 void test_typeAliasCannotReferenceItself_19459() { 5533 void test_typeAliasCannotReferenceItself_19459() {
5975 // A complex example involving multiple classes. This is legal, since 5534 // A complex example involving multiple classes. This is legal, since
5976 // typedef F references itself only via a class. 5535 // typedef F references itself only via a class.
5977 Source source = addSource(r''' 5536 Source source = addSource(r'''
5978 class A<B, C> {} 5537 class A<B, C> {}
5979 abstract class D { 5538 abstract class D {
5980 f(E e); 5539 f(E e);
5981 } 5540 }
5982 abstract class E extends A<dynamic, F> {} 5541 abstract class E extends A<dynamic, F> {}
5983 typedef D F(); 5542 typedef D F();
5984 '''); 5543 ''');
5985 computeLibrarySourceErrors(source);
5986 assertNoErrors(source); 5544 assertNoErrors(source);
5987 verify([source]); 5545 verify([source]);
5988 } 5546 }
5989 5547
5990 void test_typeAliasCannotReferenceItself_parameterType_named() { 5548 void test_typeAliasCannotReferenceItself_parameterType_named() {
5991 Source source = addSource("typedef A({A a});"); 5549 Source source = addSource("typedef A({A a});");
5992 computeLibrarySourceErrors(source);
5993 assertErrors( 5550 assertErrors(
5994 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); 5551 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]);
5995 verify([source]); 5552 verify([source]);
5996 } 5553 }
5997 5554
5998 void test_typeAliasCannotReferenceItself_parameterType_positional() { 5555 void test_typeAliasCannotReferenceItself_parameterType_positional() {
5999 Source source = addSource("typedef A([A a]);"); 5556 Source source = addSource("typedef A([A a]);");
6000 computeLibrarySourceErrors(source);
6001 assertErrors( 5557 assertErrors(
6002 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); 5558 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]);
6003 verify([source]); 5559 verify([source]);
6004 } 5560 }
6005 5561
6006 void test_typeAliasCannotReferenceItself_parameterType_required() { 5562 void test_typeAliasCannotReferenceItself_parameterType_required() {
6007 Source source = addSource("typedef A(A a);"); 5563 Source source = addSource("typedef A(A a);");
6008 computeLibrarySourceErrors(source);
6009 assertErrors( 5564 assertErrors(
6010 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); 5565 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]);
6011 verify([source]); 5566 verify([source]);
6012 } 5567 }
6013 5568
6014 void test_typeAliasCannotReferenceItself_parameterType_typeArgument() { 5569 void test_typeAliasCannotReferenceItself_parameterType_typeArgument() {
6015 Source source = addSource("typedef A(List<A> a);"); 5570 Source source = addSource("typedef A(List<A> a);");
6016 computeLibrarySourceErrors(source);
6017 assertErrors( 5571 assertErrors(
6018 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); 5572 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]);
6019 verify([source]); 5573 verify([source]);
6020 } 5574 }
6021 5575
6022 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() { 5576 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() {
6023 // A typedef is allowed to indirectly reference itself via a class. 5577 // A typedef is allowed to indirectly reference itself via a class.
6024 Source source = addSource(r''' 5578 Source source = addSource(r'''
6025 typedef C A(); 5579 typedef C A();
6026 typedef A B(); 5580 typedef A B();
6027 class C { 5581 class C {
6028 B a; 5582 B a;
6029 }'''); 5583 }''');
6030 computeLibrarySourceErrors(source);
6031 assertNoErrors(source); 5584 assertNoErrors(source);
6032 verify([source]); 5585 verify([source]);
6033 } 5586 }
6034 5587
6035 void test_typeAliasCannotReferenceItself_returnType() { 5588 void test_typeAliasCannotReferenceItself_returnType() {
6036 Source source = addSource("typedef A A();"); 5589 Source source = addSource("typedef A A();");
6037 computeLibrarySourceErrors(source);
6038 assertErrors( 5590 assertErrors(
6039 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); 5591 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]);
6040 verify([source]); 5592 verify([source]);
6041 } 5593 }
6042 5594
6043 void test_typeAliasCannotReferenceItself_returnType_indirect() { 5595 void test_typeAliasCannotReferenceItself_returnType_indirect() {
6044 Source source = addSource(r''' 5596 Source source = addSource(r'''
6045 typedef B A(); 5597 typedef B A();
6046 typedef A B();'''); 5598 typedef A B();''');
6047 computeLibrarySourceErrors(source);
6048 assertErrors(source, [ 5599 assertErrors(source, [
6049 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, 5600 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF,
6050 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF 5601 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF
6051 ]); 5602 ]);
6052 verify([source]); 5603 verify([source]);
6053 } 5604 }
6054 5605
6055 void test_typeAliasCannotReferenceItself_typeVariableBounds() { 5606 void test_typeAliasCannotReferenceItself_typeVariableBounds() {
6056 Source source = addSource("typedef A<T extends A>();"); 5607 Source source = addSource("typedef A<T extends A>();");
6057 computeLibrarySourceErrors(source);
6058 assertErrors( 5608 assertErrors(
6059 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); 5609 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]);
6060 verify([source]); 5610 verify([source]);
6061 } 5611 }
6062 5612
6063 void test_typeArgumentNotMatchingBounds_const() { 5613 void test_typeArgumentNotMatchingBounds_const() {
6064 Source source = addSource(r''' 5614 Source source = addSource(r'''
6065 class A {} 5615 class A {}
6066 class B {} 5616 class B {}
6067 class G<E extends A> { 5617 class G<E extends A> {
6068 const G(); 5618 const G();
6069 } 5619 }
6070 f() { return const G<B>(); }'''); 5620 f() { return const G<B>(); }''');
6071 computeLibrarySourceErrors(source);
6072 assertErrors( 5621 assertErrors(
6073 source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); 5622 source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
6074 verify([source]); 5623 verify([source]);
6075 } 5624 }
6076 5625
6077 void test_undefinedClass_const() { 5626 void test_undefinedClass_const() {
6078 Source source = addSource(r''' 5627 Source source = addSource(r'''
6079 f() { 5628 f() {
6080 return const A(); 5629 return const A();
6081 }'''); 5630 }''');
6082 computeLibrarySourceErrors(source);
6083 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CLASS]); 5631 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CLASS]);
6084 verify([source]); 5632 verify([source]);
6085 } 5633 }
6086 5634
6087 void test_undefinedConstructorInInitializer_explicit_named() { 5635 void test_undefinedConstructorInInitializer_explicit_named() {
6088 Source source = addSource(r''' 5636 Source source = addSource(r'''
6089 class A {} 5637 class A {}
6090 class B extends A { 5638 class B extends A {
6091 B() : super.named(); 5639 B() : super.named();
6092 }'''); 5640 }''');
6093 computeLibrarySourceErrors(source);
6094 assertErrors( 5641 assertErrors(
6095 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); 5642 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]);
6096 // no verify(), "super.named()" is not resolved 5643 // no verify(), "super.named()" is not resolved
6097 } 5644 }
6098 5645
6099 void test_undefinedConstructorInInitializer_explicit_unnamed() { 5646 void test_undefinedConstructorInInitializer_explicit_unnamed() {
6100 Source source = addSource(r''' 5647 Source source = addSource(r'''
6101 class A { 5648 class A {
6102 A.named() {} 5649 A.named() {}
6103 } 5650 }
6104 class B extends A { 5651 class B extends A {
6105 B() : super(); 5652 B() : super();
6106 }'''); 5653 }''');
6107 computeLibrarySourceErrors(source);
6108 assertErrors(source, 5654 assertErrors(source,
6109 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); 5655 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]);
6110 verify([source]); 5656 verify([source]);
6111 } 5657 }
6112 5658
6113 void test_undefinedConstructorInInitializer_implicit() { 5659 void test_undefinedConstructorInInitializer_implicit() {
6114 Source source = addSource(r''' 5660 Source source = addSource(r'''
6115 class A { 5661 class A {
6116 A.named() {} 5662 A.named() {}
6117 } 5663 }
6118 class B extends A { 5664 class B extends A {
6119 B(); 5665 B();
6120 }'''); 5666 }''');
6121 computeLibrarySourceErrors(source);
6122 assertErrors(source, 5667 assertErrors(source,
6123 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); 5668 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]);
6124 verify([source]); 5669 verify([source]);
6125 } 5670 }
6126 5671
6127 void test_undefinedNamedParameter() { 5672 void test_undefinedNamedParameter() {
6128 Source source = addSource(r''' 5673 Source source = addSource(r'''
6129 class A { 5674 class A {
6130 const A(); 5675 const A();
6131 } 5676 }
6132 main() { 5677 main() {
6133 const A(p: 0); 5678 const A(p: 0);
6134 }'''); 5679 }''');
6135 computeLibrarySourceErrors(source);
6136 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]); 5680 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]);
6137 // no verify(), 'p' is not resolved 5681 // no verify(), 'p' is not resolved
6138 } 5682 }
6139 5683
6140 void test_uriDoesNotExist_export() { 5684 void test_uriDoesNotExist_export() {
6141 Source source = addSource("export 'unknown.dart';"); 5685 Source source = addSource("export 'unknown.dart';");
6142 computeLibrarySourceErrors(source);
6143 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 5686 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
6144 } 5687 }
6145 5688
6146 void test_uriDoesNotExist_import() { 5689 void test_uriDoesNotExist_import() {
6147 Source source = addSource("import 'unknown.dart';"); 5690 Source source = addSource("import 'unknown.dart';");
6148 computeLibrarySourceErrors(source);
6149 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 5691 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
6150 } 5692 }
6151 5693
6152 void test_uriDoesNotExist_import_appears_after_deleting_target() { 5694 void test_uriDoesNotExist_import_appears_after_deleting_target() {
6153 Source test = addSource("import 'target.dart';"); 5695 Source test = addSource("import 'target.dart';");
6154 Source target = addNamedSource("/target.dart", ""); 5696 Source target = addNamedSource("/target.dart", "");
6155 computeLibrarySourceErrors(test);
6156 assertErrors(test, [HintCode.UNUSED_IMPORT]); 5697 assertErrors(test, [HintCode.UNUSED_IMPORT]);
6157 5698
6158 // Remove the overlay in the same way as AnalysisServer. 5699 // Remove the overlay in the same way as AnalysisServer.
6159 analysisContext2.setContents(target, null); 5700 analysisContext2.setContents(target, null);
6160 ChangeSet changeSet = new ChangeSet()..removedSource(target); 5701 ChangeSet changeSet = new ChangeSet()..removedSource(target);
6161 analysisContext2.applyChanges(changeSet); 5702 analysisContext2.applyChanges(changeSet);
6162 5703
6163 computeLibrarySourceErrors(test);
6164 assertErrors(test, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 5704 assertErrors(test, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
6165 } 5705 }
6166 5706
6167 void test_uriDoesNotExist_import_disappears_when_fixed() { 5707 void test_uriDoesNotExist_import_disappears_when_fixed() {
6168 Source source = addSource("import 'target.dart';"); 5708 Source source = addSource("import 'target.dart';");
6169 computeLibrarySourceErrors(source);
6170 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 5709 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
6171 5710
6172 // Check that the file is represented as missing. 5711 // Check that the file is represented as missing.
6173 Source target = analysisContext2 5712 Source target = analysisContext2
6174 .getSourcesWithFullName(resourceProvider.convertPath("/target.dart")) 5713 .getSourcesWithFullName(resourceProvider.convertPath("/target.dart"))
6175 .first; 5714 .first;
6176 expect(analysisContext2.getModificationStamp(target), -1); 5715 expect(analysisContext2.getModificationStamp(target), -1);
6177 5716
6178 // Add an overlay in the same way as AnalysisServer. 5717 // Add an overlay in the same way as AnalysisServer.
6179 analysisContext2 5718 analysisContext2
6180 ..setContents(target, "") 5719 ..setContents(target, "")
6181 ..handleContentsChanged(target, null, "", true); 5720 ..handleContentsChanged(target, null, "", true);
6182 5721
6183 // Make sure the error goes away. 5722 // Make sure the error goes away.
6184 computeLibrarySourceErrors(source);
6185 assertErrors(source, [HintCode.UNUSED_IMPORT]); 5723 assertErrors(source, [HintCode.UNUSED_IMPORT]);
6186 } 5724 }
6187 5725
6188 void test_uriDoesNotExist_part() { 5726 void test_uriDoesNotExist_part() {
6189 Source source = addSource(r''' 5727 Source source = addSource(r'''
6190 library lib; 5728 library lib;
6191 part 'unknown.dart';'''); 5729 part 'unknown.dart';''');
6192 computeLibrarySourceErrors(source);
6193 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 5730 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
6194 } 5731 }
6195 5732
6196 void test_uriWithInterpolation_constant() { 5733 void test_uriWithInterpolation_constant() {
6197 Source source = addSource("import 'stuff_\$platform.dart';"); 5734 Source source = addSource("import 'stuff_\$platform.dart';");
6198 computeLibrarySourceErrors(source);
6199 assertErrors(source, [ 5735 assertErrors(source, [
6200 CompileTimeErrorCode.URI_WITH_INTERPOLATION, 5736 CompileTimeErrorCode.URI_WITH_INTERPOLATION,
6201 StaticWarningCode.UNDEFINED_IDENTIFIER 5737 StaticWarningCode.UNDEFINED_IDENTIFIER
6202 ]); 5738 ]);
6203 // We cannot verify resolution with an unresolvable 5739 // We cannot verify resolution with an unresolvable
6204 // URI: 'stuff_$platform.dart' 5740 // URI: 'stuff_$platform.dart'
6205 } 5741 }
6206 5742
6207 void test_uriWithInterpolation_nonConstant() { 5743 void test_uriWithInterpolation_nonConstant() {
6208 Source source = addSource(r''' 5744 Source source = addSource(r'''
6209 library lib; 5745 library lib;
6210 part '${'a'}.dart';'''); 5746 part '${'a'}.dart';''');
6211 computeLibrarySourceErrors(source);
6212 assertErrors(source, [CompileTimeErrorCode.URI_WITH_INTERPOLATION]); 5747 assertErrors(source, [CompileTimeErrorCode.URI_WITH_INTERPOLATION]);
6213 // We cannot verify resolution with an unresolvable URI: '${'a'}.dart' 5748 // We cannot verify resolution with an unresolvable URI: '${'a'}.dart'
6214 } 5749 }
6215 5750
6216 void test_wrongNumberOfParametersForOperator1() { 5751 void test_wrongNumberOfParametersForOperator1() {
6217 _check_wrongNumberOfParametersForOperator1("<"); 5752 _check_wrongNumberOfParametersForOperator1("<");
6218 _check_wrongNumberOfParametersForOperator1(">"); 5753 _check_wrongNumberOfParametersForOperator1(">");
6219 _check_wrongNumberOfParametersForOperator1("<="); 5754 _check_wrongNumberOfParametersForOperator1("<=");
6220 _check_wrongNumberOfParametersForOperator1(">="); 5755 _check_wrongNumberOfParametersForOperator1(">=");
6221 _check_wrongNumberOfParametersForOperator1("+"); 5756 _check_wrongNumberOfParametersForOperator1("+");
6222 _check_wrongNumberOfParametersForOperator1("/"); 5757 _check_wrongNumberOfParametersForOperator1("/");
6223 _check_wrongNumberOfParametersForOperator1("~/"); 5758 _check_wrongNumberOfParametersForOperator1("~/");
6224 _check_wrongNumberOfParametersForOperator1("*"); 5759 _check_wrongNumberOfParametersForOperator1("*");
6225 _check_wrongNumberOfParametersForOperator1("%"); 5760 _check_wrongNumberOfParametersForOperator1("%");
6226 _check_wrongNumberOfParametersForOperator1("|"); 5761 _check_wrongNumberOfParametersForOperator1("|");
6227 _check_wrongNumberOfParametersForOperator1("^"); 5762 _check_wrongNumberOfParametersForOperator1("^");
6228 _check_wrongNumberOfParametersForOperator1("&"); 5763 _check_wrongNumberOfParametersForOperator1("&");
6229 _check_wrongNumberOfParametersForOperator1("<<"); 5764 _check_wrongNumberOfParametersForOperator1("<<");
6230 _check_wrongNumberOfParametersForOperator1(">>"); 5765 _check_wrongNumberOfParametersForOperator1(">>");
6231 _check_wrongNumberOfParametersForOperator1("[]"); 5766 _check_wrongNumberOfParametersForOperator1("[]");
6232 } 5767 }
6233 5768
6234 void test_wrongNumberOfParametersForOperator_minus() { 5769 void test_wrongNumberOfParametersForOperator_minus() {
6235 Source source = addSource(r''' 5770 Source source = addSource(r'''
6236 class A { 5771 class A {
6237 operator -(a, b) {} 5772 operator -(a, b) {}
6238 }'''); 5773 }''');
6239 computeLibrarySourceErrors(source);
6240 assertErrors(source, 5774 assertErrors(source,
6241 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS]); 5775 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS]);
6242 verify([source]); 5776 verify([source]);
6243 reset(); 5777 reset();
6244 } 5778 }
6245 5779
6246 void test_wrongNumberOfParametersForOperator_tilde() { 5780 void test_wrongNumberOfParametersForOperator_tilde() {
6247 _check_wrongNumberOfParametersForOperator("~", "a"); 5781 _check_wrongNumberOfParametersForOperator("~", "a");
6248 _check_wrongNumberOfParametersForOperator("~", "a, b"); 5782 _check_wrongNumberOfParametersForOperator("~", "a, b");
6249 } 5783 }
6250 5784
6251 void test_wrongNumberOfParametersForSetter_function_named() { 5785 void test_wrongNumberOfParametersForSetter_function_named() {
6252 Source source = addSource("set x({p}) {}"); 5786 Source source = addSource("set x({p}) {}");
6253 computeLibrarySourceErrors(source);
6254 assertErrors( 5787 assertErrors(
6255 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); 5788 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
6256 verify([source]); 5789 verify([source]);
6257 } 5790 }
6258 5791
6259 void test_wrongNumberOfParametersForSetter_function_optional() { 5792 void test_wrongNumberOfParametersForSetter_function_optional() {
6260 Source source = addSource("set x([p]) {}"); 5793 Source source = addSource("set x([p]) {}");
6261 computeLibrarySourceErrors(source);
6262 assertErrors( 5794 assertErrors(
6263 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); 5795 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
6264 verify([source]); 5796 verify([source]);
6265 } 5797 }
6266 5798
6267 void test_wrongNumberOfParametersForSetter_function_tooFew() { 5799 void test_wrongNumberOfParametersForSetter_function_tooFew() {
6268 Source source = addSource("set x() {}"); 5800 Source source = addSource("set x() {}");
6269 computeLibrarySourceErrors(source);
6270 assertErrors( 5801 assertErrors(
6271 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); 5802 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
6272 verify([source]); 5803 verify([source]);
6273 } 5804 }
6274 5805
6275 void test_wrongNumberOfParametersForSetter_function_tooMany() { 5806 void test_wrongNumberOfParametersForSetter_function_tooMany() {
6276 Source source = addSource("set x(a, b) {}"); 5807 Source source = addSource("set x(a, b) {}");
6277 computeLibrarySourceErrors(source);
6278 assertErrors( 5808 assertErrors(
6279 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); 5809 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
6280 verify([source]); 5810 verify([source]);
6281 } 5811 }
6282 5812
6283 void test_wrongNumberOfParametersForSetter_method_named() { 5813 void test_wrongNumberOfParametersForSetter_method_named() {
6284 Source source = addSource(r''' 5814 Source source = addSource(r'''
6285 class A { 5815 class A {
6286 set x({p}) {} 5816 set x({p}) {}
6287 }'''); 5817 }''');
6288 computeLibrarySourceErrors(source);
6289 assertErrors( 5818 assertErrors(
6290 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); 5819 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
6291 verify([source]); 5820 verify([source]);
6292 } 5821 }
6293 5822
6294 void test_wrongNumberOfParametersForSetter_method_optional() { 5823 void test_wrongNumberOfParametersForSetter_method_optional() {
6295 Source source = addSource(r''' 5824 Source source = addSource(r'''
6296 class A { 5825 class A {
6297 set x([p]) {} 5826 set x([p]) {}
6298 }'''); 5827 }''');
6299 computeLibrarySourceErrors(source);
6300 assertErrors( 5828 assertErrors(
6301 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); 5829 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
6302 verify([source]); 5830 verify([source]);
6303 } 5831 }
6304 5832
6305 void test_wrongNumberOfParametersForSetter_method_tooFew() { 5833 void test_wrongNumberOfParametersForSetter_method_tooFew() {
6306 Source source = addSource(r''' 5834 Source source = addSource(r'''
6307 class A { 5835 class A {
6308 set x() {} 5836 set x() {}
6309 }'''); 5837 }''');
6310 computeLibrarySourceErrors(source);
6311 assertErrors( 5838 assertErrors(
6312 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); 5839 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
6313 verify([source]); 5840 verify([source]);
6314 } 5841 }
6315 5842
6316 void test_wrongNumberOfParametersForSetter_method_tooMany() { 5843 void test_wrongNumberOfParametersForSetter_method_tooMany() {
6317 Source source = addSource(r''' 5844 Source source = addSource(r'''
6318 class A { 5845 class A {
6319 set x(a, b) {} 5846 set x(a, b) {}
6320 }'''); 5847 }''');
6321 computeLibrarySourceErrors(source);
6322 assertErrors( 5848 assertErrors(
6323 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); 5849 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
6324 verify([source]); 5850 verify([source]);
6325 } 5851 }
6326 5852
6327 void test_yield_used_as_identifier_in_async_method() { 5853 void test_yield_used_as_identifier_in_async_method() {
6328 Source source = addSource(''' 5854 Source source = addSource('''
6329 f() async { 5855 f() async {
6330 var yield = 1; 5856 var yield = 1;
6331 } 5857 }
6332 '''); 5858 ''');
6333 computeLibrarySourceErrors(source);
6334 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 5859 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
6335 verify([source]); 5860 verify([source]);
6336 } 5861 }
6337 5862
6338 void test_yield_used_as_identifier_in_async_star_method() { 5863 void test_yield_used_as_identifier_in_async_star_method() {
6339 Source source = addSource(''' 5864 Source source = addSource('''
6340 f() async* { 5865 f() async* {
6341 var yield = 1; 5866 var yield = 1;
6342 } 5867 }
6343 '''); 5868 ''');
6344 computeLibrarySourceErrors(source);
6345 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 5869 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
6346 verify([source]); 5870 verify([source]);
6347 } 5871 }
6348 5872
6349 void test_yield_used_as_identifier_in_sync_star_method() { 5873 void test_yield_used_as_identifier_in_sync_star_method() {
6350 Source source = addSource(''' 5874 Source source = addSource('''
6351 f() sync* { 5875 f() sync* {
6352 var yield = 1; 5876 var yield = 1;
6353 } 5877 }
6354 '''); 5878 ''');
6355 computeLibrarySourceErrors(source);
6356 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 5879 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
6357 verify([source]); 5880 verify([source]);
6358 } 5881 }
6359 5882
6360 void _check_constEvalThrowsException_binary_null(String expr, bool resolved) { 5883 void _check_constEvalThrowsException_binary_null(String expr, bool resolved) {
6361 Source source = addSource("const C = $expr;"); 5884 Source source = addSource("const C = $expr;");
6362 computeLibrarySourceErrors(source);
6363 if (resolved) { 5885 if (resolved) {
6364 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); 5886 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
6365 verify([source]); 5887 verify([source]);
6366 } else { 5888 } else {
6367 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); 5889 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
6368 // no verify(), 'null x' is not resolved 5890 // no verify(), 'null x' is not resolved
6369 } 5891 }
6370 reset(); 5892 reset();
6371 } 5893 }
6372 5894
6373 void _check_constEvalTypeBool_withParameter_binary(String expr) { 5895 void _check_constEvalTypeBool_withParameter_binary(String expr) {
6374 Source source = addSource(''' 5896 Source source = addSource('''
6375 class A { 5897 class A {
6376 final a; 5898 final a;
6377 const A(bool p) : a = $expr; 5899 const A(bool p) : a = $expr;
6378 }'''); 5900 }''');
6379 computeLibrarySourceErrors(source);
6380 assertErrors(source, [ 5901 assertErrors(source, [
6381 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 5902 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
6382 StaticTypeWarningCode.NON_BOOL_OPERAND 5903 StaticTypeWarningCode.NON_BOOL_OPERAND
6383 ]); 5904 ]);
6384 verify([source]); 5905 verify([source]);
6385 reset(); 5906 reset();
6386 } 5907 }
6387 5908
6388 void _check_constEvalTypeInt_withParameter_binary(String expr) { 5909 void _check_constEvalTypeInt_withParameter_binary(String expr) {
6389 Source source = addSource(''' 5910 Source source = addSource('''
6390 class A { 5911 class A {
6391 final a; 5912 final a;
6392 const A(int p) : a = $expr; 5913 const A(int p) : a = $expr;
6393 }'''); 5914 }''');
6394 computeLibrarySourceErrors(source);
6395 assertErrors(source, [ 5915 assertErrors(source, [
6396 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, 5916 CompileTimeErrorCode.CONST_EVAL_TYPE_INT,
6397 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE 5917 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE
6398 ]); 5918 ]);
6399 verify([source]); 5919 verify([source]);
6400 reset(); 5920 reset();
6401 } 5921 }
6402 5922
6403 void _check_constEvalTypeNum_withParameter_binary(String expr) { 5923 void _check_constEvalTypeNum_withParameter_binary(String expr) {
6404 Source source = addSource(''' 5924 Source source = addSource('''
6405 class A { 5925 class A {
6406 final a; 5926 final a;
6407 const A(num p) : a = $expr; 5927 const A(num p) : a = $expr;
6408 }'''); 5928 }''');
6409 computeLibrarySourceErrors(source);
6410 assertErrors(source, [ 5929 assertErrors(source, [
6411 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, 5930 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM,
6412 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE 5931 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE
6413 ]); 5932 ]);
6414 verify([source]); 5933 verify([source]);
6415 reset(); 5934 reset();
6416 } 5935 }
6417 5936
6418 void _check_wrongNumberOfParametersForOperator( 5937 void _check_wrongNumberOfParametersForOperator(
6419 String name, String parameters) { 5938 String name, String parameters) {
6420 Source source = addSource(''' 5939 Source source = addSource('''
6421 class A { 5940 class A {
6422 operator $name($parameters) {} 5941 operator $name($parameters) {}
6423 }'''); 5942 }''');
6424 computeLibrarySourceErrors(source);
6425 assertErrors( 5943 assertErrors(
6426 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); 5944 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]);
6427 verify([source]); 5945 verify([source]);
6428 reset(); 5946 reset();
6429 } 5947 }
6430 5948
6431 void _check_wrongNumberOfParametersForOperator1(String name) { 5949 void _check_wrongNumberOfParametersForOperator1(String name) {
6432 _check_wrongNumberOfParametersForOperator(name, ""); 5950 _check_wrongNumberOfParametersForOperator(name, "");
6433 _check_wrongNumberOfParametersForOperator(name, "a, b"); 5951 _check_wrongNumberOfParametersForOperator(name, "a, b");
6434 } 5952 }
6435 } 5953 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698