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

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

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

Powered by Google App Engine
This is Rietveld 408576698