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

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

Issue 2624793002: Make error producing tests ansynchronous. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.simple_resolver_test; 5 library analyzer.test.generated.simple_resolver_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/dart/element/type.dart'; 11 import 'package:analyzer/dart/element/type.dart';
12 import 'package:analyzer/exception/exception.dart'; 12 import 'package:analyzer/exception/exception.dart';
13 import 'package:analyzer/src/error/codes.dart'; 13 import 'package:analyzer/src/error/codes.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 14 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/source_io.dart'; 15 import 'package:analyzer/src/generated/source_io.dart';
16 import 'package:test/test.dart'; 16 import 'package:test/test.dart';
17 import 'package:test_reflective_loader/test_reflective_loader.dart'; 17 import 'package:test_reflective_loader/test_reflective_loader.dart';
18 18
19 import 'resolver_test_case.dart'; 19 import 'resolver_test_case.dart';
20 import 'test_support.dart'; 20 import 'test_support.dart';
21 21
22 main() { 22 main() {
23 defineReflectiveSuite(() { 23 defineReflectiveSuite(() {
24 defineReflectiveTests(SimpleResolverTest); 24 defineReflectiveTests(SimpleResolverTest);
25 }); 25 });
26 } 26 }
27 27
28 @reflectiveTest 28 @reflectiveTest
29 class SimpleResolverTest extends ResolverTestCase { 29 class SimpleResolverTest extends ResolverTestCase {
30 void test_argumentResolution_required_matching() { 30 test_argumentResolution_required_matching() async {
31 Source source = addSource(r''' 31 Source source = addSource(r'''
32 class A { 32 class A {
33 void f() { 33 void f() {
34 g(1, 2, 3); 34 g(1, 2, 3);
35 } 35 }
36 void g(a, b, c) {} 36 void g(a, b, c) {}
37 }'''); 37 }''');
38 _validateArgumentResolution(source, [0, 1, 2]); 38 _validateArgumentResolution(source, [0, 1, 2]);
39 } 39 }
40 40
41 void test_argumentResolution_required_tooFew() { 41 test_argumentResolution_required_tooFew() async {
42 Source source = addSource(r''' 42 Source source = addSource(r'''
43 class A { 43 class A {
44 void f() { 44 void f() {
45 g(1, 2); 45 g(1, 2);
46 } 46 }
47 void g(a, b, c) {} 47 void g(a, b, c) {}
48 }'''); 48 }''');
49 _validateArgumentResolution(source, [0, 1]); 49 _validateArgumentResolution(source, [0, 1]);
50 } 50 }
51 51
52 void test_argumentResolution_required_tooMany() { 52 test_argumentResolution_required_tooMany() async {
53 Source source = addSource(r''' 53 Source source = addSource(r'''
54 class A { 54 class A {
55 void f() { 55 void f() {
56 g(1, 2, 3); 56 g(1, 2, 3);
57 } 57 }
58 void g(a, b) {} 58 void g(a, b) {}
59 }'''); 59 }''');
60 _validateArgumentResolution(source, [0, 1, -1]); 60 _validateArgumentResolution(source, [0, 1, -1]);
61 } 61 }
62 62
63 void test_argumentResolution_requiredAndNamed_extra() { 63 test_argumentResolution_requiredAndNamed_extra() async {
64 Source source = addSource(r''' 64 Source source = addSource(r'''
65 class A { 65 class A {
66 void f() { 66 void f() {
67 g(1, 2, c: 3, d: 4); 67 g(1, 2, c: 3, d: 4);
68 } 68 }
69 void g(a, b, {c}) {} 69 void g(a, b, {c}) {}
70 }'''); 70 }''');
71 _validateArgumentResolution(source, [0, 1, 2, -1]); 71 _validateArgumentResolution(source, [0, 1, 2, -1]);
72 } 72 }
73 73
74 void test_argumentResolution_requiredAndNamed_matching() { 74 test_argumentResolution_requiredAndNamed_matching() async {
75 Source source = addSource(r''' 75 Source source = addSource(r'''
76 class A { 76 class A {
77 void f() { 77 void f() {
78 g(1, 2, c: 3); 78 g(1, 2, c: 3);
79 } 79 }
80 void g(a, b, {c}) {} 80 void g(a, b, {c}) {}
81 }'''); 81 }''');
82 _validateArgumentResolution(source, [0, 1, 2]); 82 _validateArgumentResolution(source, [0, 1, 2]);
83 } 83 }
84 84
85 void test_argumentResolution_requiredAndNamed_missing() { 85 test_argumentResolution_requiredAndNamed_missing() async {
86 Source source = addSource(r''' 86 Source source = addSource(r'''
87 class A { 87 class A {
88 void f() { 88 void f() {
89 g(1, 2, d: 3); 89 g(1, 2, d: 3);
90 } 90 }
91 void g(a, b, {c, d}) {} 91 void g(a, b, {c, d}) {}
92 }'''); 92 }''');
93 _validateArgumentResolution(source, [0, 1, 3]); 93 _validateArgumentResolution(source, [0, 1, 3]);
94 } 94 }
95 95
96 void test_argumentResolution_requiredAndPositional_fewer() { 96 test_argumentResolution_requiredAndPositional_fewer() async {
97 Source source = addSource(r''' 97 Source source = addSource(r'''
98 class A { 98 class A {
99 void f() { 99 void f() {
100 g(1, 2, 3); 100 g(1, 2, 3);
101 } 101 }
102 void g(a, b, [c, d]) {} 102 void g(a, b, [c, d]) {}
103 }'''); 103 }''');
104 _validateArgumentResolution(source, [0, 1, 2]); 104 _validateArgumentResolution(source, [0, 1, 2]);
105 } 105 }
106 106
107 void test_argumentResolution_requiredAndPositional_matching() { 107 test_argumentResolution_requiredAndPositional_matching() async {
108 Source source = addSource(r''' 108 Source source = addSource(r'''
109 class A { 109 class A {
110 void f() { 110 void f() {
111 g(1, 2, 3, 4); 111 g(1, 2, 3, 4);
112 } 112 }
113 void g(a, b, [c, d]) {} 113 void g(a, b, [c, d]) {}
114 }'''); 114 }''');
115 _validateArgumentResolution(source, [0, 1, 2, 3]); 115 _validateArgumentResolution(source, [0, 1, 2, 3]);
116 } 116 }
117 117
118 void test_argumentResolution_requiredAndPositional_more() { 118 test_argumentResolution_requiredAndPositional_more() async {
119 Source source = addSource(r''' 119 Source source = addSource(r'''
120 class A { 120 class A {
121 void f() { 121 void f() {
122 g(1, 2, 3, 4); 122 g(1, 2, 3, 4);
123 } 123 }
124 void g(a, b, [c]) {} 124 void g(a, b, [c]) {}
125 }'''); 125 }''');
126 _validateArgumentResolution(source, [0, 1, 2, -1]); 126 _validateArgumentResolution(source, [0, 1, 2, -1]);
127 } 127 }
128 128
129 void test_argumentResolution_setter_propagated() { 129 test_argumentResolution_setter_propagated() async {
130 Source source = addSource(r''' 130 Source source = addSource(r'''
131 main() { 131 main() {
132 var a = new A(); 132 var a = new A();
133 a.sss = 0; 133 a.sss = 0;
134 } 134 }
135 class A { 135 class A {
136 set sss(x) {} 136 set sss(x) {}
137 }'''); 137 }''');
138 LibraryElement library = resolve2(source); 138 LibraryElement library = resolve2(source);
139 CompilationUnitElement unit = library.definingCompilationUnit; 139 CompilationUnitElement unit = library.definingCompilationUnit;
(...skipping 12 matching lines...) Expand all
152 expect(rhs.staticParameterElement, isNull); 152 expect(rhs.staticParameterElement, isNull);
153 ParameterElement parameter = rhs.propagatedParameterElement; 153 ParameterElement parameter = rhs.propagatedParameterElement;
154 expect(parameter, isNotNull); 154 expect(parameter, isNotNull);
155 expect(parameter.displayName, "x"); 155 expect(parameter.displayName, "x");
156 // validate 156 // validate
157 ClassElement classA = unit.types[0]; 157 ClassElement classA = unit.types[0];
158 PropertyAccessorElement setter = classA.accessors[0]; 158 PropertyAccessorElement setter = classA.accessors[0];
159 expect(setter.parameters[0], same(parameter)); 159 expect(setter.parameters[0], same(parameter));
160 } 160 }
161 161
162 void test_argumentResolution_setter_propagated_propertyAccess() { 162 test_argumentResolution_setter_propagated_propertyAccess() async {
163 Source source = addSource(r''' 163 Source source = addSource(r'''
164 main() { 164 main() {
165 var a = new A(); 165 var a = new A();
166 a.b.sss = 0; 166 a.b.sss = 0;
167 } 167 }
168 class A { 168 class A {
169 B b = new B(); 169 B b = new B();
170 } 170 }
171 class B { 171 class B {
172 set sss(x) {} 172 set sss(x) {}
(...skipping 15 matching lines...) Expand all
188 expect(rhs.staticParameterElement, isNull); 188 expect(rhs.staticParameterElement, isNull);
189 ParameterElement parameter = rhs.propagatedParameterElement; 189 ParameterElement parameter = rhs.propagatedParameterElement;
190 expect(parameter, isNotNull); 190 expect(parameter, isNotNull);
191 expect(parameter.displayName, "x"); 191 expect(parameter.displayName, "x");
192 // validate 192 // validate
193 ClassElement classB = unit.types[1]; 193 ClassElement classB = unit.types[1];
194 PropertyAccessorElement setter = classB.accessors[0]; 194 PropertyAccessorElement setter = classB.accessors[0];
195 expect(setter.parameters[0], same(parameter)); 195 expect(setter.parameters[0], same(parameter));
196 } 196 }
197 197
198 void test_argumentResolution_setter_static() { 198 test_argumentResolution_setter_static() async {
199 Source source = addSource(r''' 199 Source source = addSource(r'''
200 main() { 200 main() {
201 A a = new A(); 201 A a = new A();
202 a.sss = 0; 202 a.sss = 0;
203 } 203 }
204 class A { 204 class A {
205 set sss(x) {} 205 set sss(x) {}
206 }'''); 206 }''');
207 LibraryElement library = resolve2(source); 207 LibraryElement library = resolve2(source);
208 CompilationUnitElement unit = library.definingCompilationUnit; 208 CompilationUnitElement unit = library.definingCompilationUnit;
(...skipping 11 matching lines...) Expand all
220 Expression rhs = assignment.rightHandSide; 220 Expression rhs = assignment.rightHandSide;
221 ParameterElement parameter = rhs.staticParameterElement; 221 ParameterElement parameter = rhs.staticParameterElement;
222 expect(parameter, isNotNull); 222 expect(parameter, isNotNull);
223 expect(parameter.displayName, "x"); 223 expect(parameter.displayName, "x");
224 // validate 224 // validate
225 ClassElement classA = unit.types[0]; 225 ClassElement classA = unit.types[0];
226 PropertyAccessorElement setter = classA.accessors[0]; 226 PropertyAccessorElement setter = classA.accessors[0];
227 expect(setter.parameters[0], same(parameter)); 227 expect(setter.parameters[0], same(parameter));
228 } 228 }
229 229
230 void test_argumentResolution_setter_static_propertyAccess() { 230 test_argumentResolution_setter_static_propertyAccess() async {
231 Source source = addSource(r''' 231 Source source = addSource(r'''
232 main() { 232 main() {
233 A a = new A(); 233 A a = new A();
234 a.b.sss = 0; 234 a.b.sss = 0;
235 } 235 }
236 class A { 236 class A {
237 B b = new B(); 237 B b = new B();
238 } 238 }
239 class B { 239 class B {
240 set sss(x) {} 240 set sss(x) {}
(...skipping 14 matching lines...) Expand all
255 Expression rhs = assignment.rightHandSide; 255 Expression rhs = assignment.rightHandSide;
256 ParameterElement parameter = rhs.staticParameterElement; 256 ParameterElement parameter = rhs.staticParameterElement;
257 expect(parameter, isNotNull); 257 expect(parameter, isNotNull);
258 expect(parameter.displayName, "x"); 258 expect(parameter.displayName, "x");
259 // validate 259 // validate
260 ClassElement classB = unit.types[1]; 260 ClassElement classB = unit.types[1];
261 PropertyAccessorElement setter = classB.accessors[0]; 261 PropertyAccessorElement setter = classB.accessors[0];
262 expect(setter.parameters[0], same(parameter)); 262 expect(setter.parameters[0], same(parameter));
263 } 263 }
264 264
265 void test_breakTarget_labeled() { 265 test_breakTarget_labeled() async {
266 // Verify that the target of the label is correctly found and is recorded 266 // Verify that the target of the label is correctly found and is recorded
267 // as the unlabeled portion of the statement. 267 // as the unlabeled portion of the statement.
268 String text = r''' 268 String text = r'''
269 void f() { 269 void f() {
270 loop1: while (true) { 270 loop1: while (true) {
271 loop2: for (int i = 0; i < 10; i++) { 271 loop2: for (int i = 0; i < 10; i++) {
272 break loop1; 272 break loop1;
273 break loop2; 273 break loop2;
274 } 274 }
275 } 275 }
276 } 276 }
277 '''; 277 ''';
278 CompilationUnit unit = resolveSource(text); 278 CompilationUnit unit = resolveSource(text);
279 WhileStatement whileStatement = EngineTestCase.findNode( 279 WhileStatement whileStatement = EngineTestCase.findNode(
280 unit, text, 'while (true)', (n) => n is WhileStatement); 280 unit, text, 'while (true)', (n) => n is WhileStatement);
281 ForStatement forStatement = 281 ForStatement forStatement =
282 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); 282 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement);
283 BreakStatement break1 = EngineTestCase.findNode( 283 BreakStatement break1 = EngineTestCase.findNode(
284 unit, text, 'break loop1', (n) => n is BreakStatement); 284 unit, text, 'break loop1', (n) => n is BreakStatement);
285 BreakStatement break2 = EngineTestCase.findNode( 285 BreakStatement break2 = EngineTestCase.findNode(
286 unit, text, 'break loop2', (n) => n is BreakStatement); 286 unit, text, 'break loop2', (n) => n is BreakStatement);
287 expect(break1.target, same(whileStatement)); 287 expect(break1.target, same(whileStatement));
288 expect(break2.target, same(forStatement)); 288 expect(break2.target, same(forStatement));
289 } 289 }
290 290
291 void test_breakTarget_unlabeledBreakFromDo() { 291 test_breakTarget_unlabeledBreakFromDo() async {
292 String text = r''' 292 String text = r'''
293 void f() { 293 void f() {
294 do { 294 do {
295 break; 295 break;
296 } while (true); 296 } while (true);
297 } 297 }
298 '''; 298 ''';
299 CompilationUnit unit = resolveSource(text); 299 CompilationUnit unit = resolveSource(text);
300 DoStatement doStatement = 300 DoStatement doStatement =
301 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement); 301 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement);
302 BreakStatement breakStatement = EngineTestCase.findNode( 302 BreakStatement breakStatement = EngineTestCase.findNode(
303 unit, text, 'break', (n) => n is BreakStatement); 303 unit, text, 'break', (n) => n is BreakStatement);
304 expect(breakStatement.target, same(doStatement)); 304 expect(breakStatement.target, same(doStatement));
305 } 305 }
306 306
307 void test_breakTarget_unlabeledBreakFromFor() { 307 test_breakTarget_unlabeledBreakFromFor() async {
308 String text = r''' 308 String text = r'''
309 void f() { 309 void f() {
310 for (int i = 0; i < 10; i++) { 310 for (int i = 0; i < 10; i++) {
311 break; 311 break;
312 } 312 }
313 } 313 }
314 '''; 314 ''';
315 CompilationUnit unit = resolveSource(text); 315 CompilationUnit unit = resolveSource(text);
316 ForStatement forStatement = 316 ForStatement forStatement =
317 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); 317 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement);
318 BreakStatement breakStatement = EngineTestCase.findNode( 318 BreakStatement breakStatement = EngineTestCase.findNode(
319 unit, text, 'break', (n) => n is BreakStatement); 319 unit, text, 'break', (n) => n is BreakStatement);
320 expect(breakStatement.target, same(forStatement)); 320 expect(breakStatement.target, same(forStatement));
321 } 321 }
322 322
323 void test_breakTarget_unlabeledBreakFromForEach() { 323 test_breakTarget_unlabeledBreakFromForEach() async {
324 String text = r''' 324 String text = r'''
325 void f() { 325 void f() {
326 for (x in []) { 326 for (x in []) {
327 break; 327 break;
328 } 328 }
329 } 329 }
330 '''; 330 ''';
331 CompilationUnit unit = resolveSource(text); 331 CompilationUnit unit = resolveSource(text);
332 ForEachStatement forStatement = EngineTestCase.findNode( 332 ForEachStatement forStatement = EngineTestCase.findNode(
333 unit, text, 'for', (n) => n is ForEachStatement); 333 unit, text, 'for', (n) => n is ForEachStatement);
334 BreakStatement breakStatement = EngineTestCase.findNode( 334 BreakStatement breakStatement = EngineTestCase.findNode(
335 unit, text, 'break', (n) => n is BreakStatement); 335 unit, text, 'break', (n) => n is BreakStatement);
336 expect(breakStatement.target, same(forStatement)); 336 expect(breakStatement.target, same(forStatement));
337 } 337 }
338 338
339 void test_breakTarget_unlabeledBreakFromSwitch() { 339 test_breakTarget_unlabeledBreakFromSwitch() async {
340 String text = r''' 340 String text = r'''
341 void f() { 341 void f() {
342 while (true) { 342 while (true) {
343 switch (0) { 343 switch (0) {
344 case 0: 344 case 0:
345 break; 345 break;
346 } 346 }
347 } 347 }
348 } 348 }
349 '''; 349 ''';
350 CompilationUnit unit = resolveSource(text); 350 CompilationUnit unit = resolveSource(text);
351 SwitchStatement switchStatement = EngineTestCase.findNode( 351 SwitchStatement switchStatement = EngineTestCase.findNode(
352 unit, text, 'switch', (n) => n is SwitchStatement); 352 unit, text, 'switch', (n) => n is SwitchStatement);
353 BreakStatement breakStatement = EngineTestCase.findNode( 353 BreakStatement breakStatement = EngineTestCase.findNode(
354 unit, text, 'break', (n) => n is BreakStatement); 354 unit, text, 'break', (n) => n is BreakStatement);
355 expect(breakStatement.target, same(switchStatement)); 355 expect(breakStatement.target, same(switchStatement));
356 } 356 }
357 357
358 void test_breakTarget_unlabeledBreakFromWhile() { 358 test_breakTarget_unlabeledBreakFromWhile() async {
359 String text = r''' 359 String text = r'''
360 void f() { 360 void f() {
361 while (true) { 361 while (true) {
362 break; 362 break;
363 } 363 }
364 } 364 }
365 '''; 365 ''';
366 CompilationUnit unit = resolveSource(text); 366 CompilationUnit unit = resolveSource(text);
367 WhileStatement whileStatement = EngineTestCase.findNode( 367 WhileStatement whileStatement = EngineTestCase.findNode(
368 unit, text, 'while', (n) => n is WhileStatement); 368 unit, text, 'while', (n) => n is WhileStatement);
369 BreakStatement breakStatement = EngineTestCase.findNode( 369 BreakStatement breakStatement = EngineTestCase.findNode(
370 unit, text, 'break', (n) => n is BreakStatement); 370 unit, text, 'break', (n) => n is BreakStatement);
371 expect(breakStatement.target, same(whileStatement)); 371 expect(breakStatement.target, same(whileStatement));
372 } 372 }
373 373
374 void test_breakTarget_unlabeledBreakToOuterFunction() { 374 test_breakTarget_unlabeledBreakToOuterFunction() async {
375 // Verify that unlabeled break statements can't resolve to loops in an 375 // Verify that unlabeled break statements can't resolve to loops in an
376 // outer function. 376 // outer function.
377 String text = r''' 377 String text = r'''
378 void f() { 378 void f() {
379 while (true) { 379 while (true) {
380 void g() { 380 void g() {
381 break; 381 break;
382 } 382 }
383 } 383 }
384 } 384 }
385 '''; 385 ''';
386 CompilationUnit unit = resolveSource(text); 386 CompilationUnit unit = resolveSource(text);
387 BreakStatement breakStatement = EngineTestCase.findNode( 387 BreakStatement breakStatement = EngineTestCase.findNode(
388 unit, text, 'break', (n) => n is BreakStatement); 388 unit, text, 'break', (n) => n is BreakStatement);
389 expect(breakStatement.target, isNull); 389 expect(breakStatement.target, isNull);
390 } 390 }
391 391
392 void test_class_definesCall() { 392 test_class_definesCall() async {
393 Source source = addSource(r''' 393 Source source = addSource(r'''
394 class A { 394 class A {
395 int call(int x) { return x; } 395 int call(int x) { return x; }
396 } 396 }
397 int f(A a) { 397 int f(A a) {
398 return a(0); 398 return a(0);
399 }'''); 399 }''');
400 assertNoErrors(source); 400 await assertNoErrors(source);
401 verify([source]); 401 verify([source]);
402 } 402 }
403 403
404 void test_class_extends_implements() { 404 test_class_extends_implements() async {
405 Source source = addSource(r''' 405 Source source = addSource(r'''
406 class A extends B implements C {} 406 class A extends B implements C {}
407 class B {} 407 class B {}
408 class C {}'''); 408 class C {}''');
409 assertNoErrors(source); 409 await assertNoErrors(source);
410 verify([source]); 410 verify([source]);
411 } 411 }
412 412
413 void test_commentReference_class() { 413 test_commentReference_class() async {
414 Source source = addSource(r''' 414 Source source = addSource(r'''
415 f() {} 415 f() {}
416 /** [A] [new A] [A.n] [new A.n] [m] [f] */ 416 /** [A] [new A] [A.n] [new A.n] [m] [f] */
417 class A { 417 class A {
418 A() {} 418 A() {}
419 A.n() {} 419 A.n() {}
420 m() {} 420 m() {}
421 }'''); 421 }''');
422 assertNoErrors(source); 422 await assertNoErrors(source);
423 verify([source]); 423 verify([source]);
424 } 424 }
425 425
426 void test_commentReference_parameter() { 426 test_commentReference_parameter() async {
427 Source source = addSource(r''' 427 Source source = addSource(r'''
428 class A { 428 class A {
429 A() {} 429 A() {}
430 A.n() {} 430 A.n() {}
431 /** [e] [f] */ 431 /** [e] [f] */
432 m(e, f()) {} 432 m(e, f()) {}
433 }'''); 433 }''');
434 assertNoErrors(source); 434 await assertNoErrors(source);
435 verify([source]); 435 verify([source]);
436 } 436 }
437 437
438 void test_commentReference_singleLine() { 438 test_commentReference_singleLine() async {
439 Source source = addSource(r''' 439 Source source = addSource(r'''
440 /// [A] 440 /// [A]
441 class A {}'''); 441 class A {}''');
442 assertNoErrors(source); 442 await assertNoErrors(source);
443 verify([source]); 443 verify([source]);
444 } 444 }
445 445
446 void test_continueTarget_labeled() { 446 test_continueTarget_labeled() async {
447 // Verify that the target of the label is correctly found and is recorded 447 // Verify that the target of the label is correctly found and is recorded
448 // as the unlabeled portion of the statement. 448 // as the unlabeled portion of the statement.
449 String text = r''' 449 String text = r'''
450 void f() { 450 void f() {
451 loop1: while (true) { 451 loop1: while (true) {
452 loop2: for (int i = 0; i < 10; i++) { 452 loop2: for (int i = 0; i < 10; i++) {
453 continue loop1; 453 continue loop1;
454 continue loop2; 454 continue loop2;
455 } 455 }
456 } 456 }
457 } 457 }
458 '''; 458 ''';
459 CompilationUnit unit = resolveSource(text); 459 CompilationUnit unit = resolveSource(text);
460 WhileStatement whileStatement = EngineTestCase.findNode( 460 WhileStatement whileStatement = EngineTestCase.findNode(
461 unit, text, 'while (true)', (n) => n is WhileStatement); 461 unit, text, 'while (true)', (n) => n is WhileStatement);
462 ForStatement forStatement = 462 ForStatement forStatement =
463 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); 463 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement);
464 ContinueStatement continue1 = EngineTestCase.findNode( 464 ContinueStatement continue1 = EngineTestCase.findNode(
465 unit, text, 'continue loop1', (n) => n is ContinueStatement); 465 unit, text, 'continue loop1', (n) => n is ContinueStatement);
466 ContinueStatement continue2 = EngineTestCase.findNode( 466 ContinueStatement continue2 = EngineTestCase.findNode(
467 unit, text, 'continue loop2', (n) => n is ContinueStatement); 467 unit, text, 'continue loop2', (n) => n is ContinueStatement);
468 expect(continue1.target, same(whileStatement)); 468 expect(continue1.target, same(whileStatement));
469 expect(continue2.target, same(forStatement)); 469 expect(continue2.target, same(forStatement));
470 } 470 }
471 471
472 void test_continueTarget_unlabeledContinueFromDo() { 472 test_continueTarget_unlabeledContinueFromDo() async {
473 String text = r''' 473 String text = r'''
474 void f() { 474 void f() {
475 do { 475 do {
476 continue; 476 continue;
477 } while (true); 477 } while (true);
478 } 478 }
479 '''; 479 ''';
480 CompilationUnit unit = resolveSource(text); 480 CompilationUnit unit = resolveSource(text);
481 DoStatement doStatement = 481 DoStatement doStatement =
482 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement); 482 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement);
483 ContinueStatement continueStatement = EngineTestCase.findNode( 483 ContinueStatement continueStatement = EngineTestCase.findNode(
484 unit, text, 'continue', (n) => n is ContinueStatement); 484 unit, text, 'continue', (n) => n is ContinueStatement);
485 expect(continueStatement.target, same(doStatement)); 485 expect(continueStatement.target, same(doStatement));
486 } 486 }
487 487
488 void test_continueTarget_unlabeledContinueFromFor() { 488 test_continueTarget_unlabeledContinueFromFor() async {
489 String text = r''' 489 String text = r'''
490 void f() { 490 void f() {
491 for (int i = 0; i < 10; i++) { 491 for (int i = 0; i < 10; i++) {
492 continue; 492 continue;
493 } 493 }
494 } 494 }
495 '''; 495 ''';
496 CompilationUnit unit = resolveSource(text); 496 CompilationUnit unit = resolveSource(text);
497 ForStatement forStatement = 497 ForStatement forStatement =
498 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); 498 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement);
499 ContinueStatement continueStatement = EngineTestCase.findNode( 499 ContinueStatement continueStatement = EngineTestCase.findNode(
500 unit, text, 'continue', (n) => n is ContinueStatement); 500 unit, text, 'continue', (n) => n is ContinueStatement);
501 expect(continueStatement.target, same(forStatement)); 501 expect(continueStatement.target, same(forStatement));
502 } 502 }
503 503
504 void test_continueTarget_unlabeledContinueFromForEach() { 504 test_continueTarget_unlabeledContinueFromForEach() async {
505 String text = r''' 505 String text = r'''
506 void f() { 506 void f() {
507 for (x in []) { 507 for (x in []) {
508 continue; 508 continue;
509 } 509 }
510 } 510 }
511 '''; 511 ''';
512 CompilationUnit unit = resolveSource(text); 512 CompilationUnit unit = resolveSource(text);
513 ForEachStatement forStatement = EngineTestCase.findNode( 513 ForEachStatement forStatement = EngineTestCase.findNode(
514 unit, text, 'for', (n) => n is ForEachStatement); 514 unit, text, 'for', (n) => n is ForEachStatement);
515 ContinueStatement continueStatement = EngineTestCase.findNode( 515 ContinueStatement continueStatement = EngineTestCase.findNode(
516 unit, text, 'continue', (n) => n is ContinueStatement); 516 unit, text, 'continue', (n) => n is ContinueStatement);
517 expect(continueStatement.target, same(forStatement)); 517 expect(continueStatement.target, same(forStatement));
518 } 518 }
519 519
520 void test_continueTarget_unlabeledContinueFromWhile() { 520 test_continueTarget_unlabeledContinueFromWhile() async {
521 String text = r''' 521 String text = r'''
522 void f() { 522 void f() {
523 while (true) { 523 while (true) {
524 continue; 524 continue;
525 } 525 }
526 } 526 }
527 '''; 527 ''';
528 CompilationUnit unit = resolveSource(text); 528 CompilationUnit unit = resolveSource(text);
529 WhileStatement whileStatement = EngineTestCase.findNode( 529 WhileStatement whileStatement = EngineTestCase.findNode(
530 unit, text, 'while', (n) => n is WhileStatement); 530 unit, text, 'while', (n) => n is WhileStatement);
531 ContinueStatement continueStatement = EngineTestCase.findNode( 531 ContinueStatement continueStatement = EngineTestCase.findNode(
532 unit, text, 'continue', (n) => n is ContinueStatement); 532 unit, text, 'continue', (n) => n is ContinueStatement);
533 expect(continueStatement.target, same(whileStatement)); 533 expect(continueStatement.target, same(whileStatement));
534 } 534 }
535 535
536 void test_continueTarget_unlabeledContinueSkipsSwitch() { 536 test_continueTarget_unlabeledContinueSkipsSwitch() async {
537 String text = r''' 537 String text = r'''
538 void f() { 538 void f() {
539 while (true) { 539 while (true) {
540 switch (0) { 540 switch (0) {
541 case 0: 541 case 0:
542 continue; 542 continue;
543 } 543 }
544 } 544 }
545 } 545 }
546 '''; 546 ''';
547 CompilationUnit unit = resolveSource(text); 547 CompilationUnit unit = resolveSource(text);
548 WhileStatement whileStatement = EngineTestCase.findNode( 548 WhileStatement whileStatement = EngineTestCase.findNode(
549 unit, text, 'while', (n) => n is WhileStatement); 549 unit, text, 'while', (n) => n is WhileStatement);
550 ContinueStatement continueStatement = EngineTestCase.findNode( 550 ContinueStatement continueStatement = EngineTestCase.findNode(
551 unit, text, 'continue', (n) => n is ContinueStatement); 551 unit, text, 'continue', (n) => n is ContinueStatement);
552 expect(continueStatement.target, same(whileStatement)); 552 expect(continueStatement.target, same(whileStatement));
553 } 553 }
554 554
555 void test_continueTarget_unlabeledContinueToOuterFunction() { 555 test_continueTarget_unlabeledContinueToOuterFunction() async {
556 // Verify that unlabeled continue statements can't resolve to loops in an 556 // Verify that unlabeled continue statements can't resolve to loops in an
557 // outer function. 557 // outer function.
558 String text = r''' 558 String text = r'''
559 void f() { 559 void f() {
560 while (true) { 560 while (true) {
561 void g() { 561 void g() {
562 continue; 562 continue;
563 } 563 }
564 } 564 }
565 } 565 }
566 '''; 566 ''';
567 CompilationUnit unit = resolveSource(text); 567 CompilationUnit unit = resolveSource(text);
568 ContinueStatement continueStatement = EngineTestCase.findNode( 568 ContinueStatement continueStatement = EngineTestCase.findNode(
569 unit, text, 'continue', (n) => n is ContinueStatement); 569 unit, text, 'continue', (n) => n is ContinueStatement);
570 expect(continueStatement.target, isNull); 570 expect(continueStatement.target, isNull);
571 } 571 }
572 572
573 void test_empty() { 573 test_empty() async {
574 Source source = addSource(""); 574 Source source = addSource("");
575 assertNoErrors(source); 575 await assertNoErrors(source);
576 verify([source]); 576 verify([source]);
577 } 577 }
578 578
579 void test_entryPoint_exported() { 579 test_entryPoint_exported() async {
580 addNamedSource( 580 addNamedSource(
581 "/two.dart", 581 "/two.dart",
582 r''' 582 r'''
583 library two; 583 library two;
584 main() {}'''); 584 main() {}''');
585 Source source = addNamedSource( 585 Source source = addNamedSource(
586 "/one.dart", 586 "/one.dart",
587 r''' 587 r'''
588 library one; 588 library one;
589 export 'two.dart';'''); 589 export 'two.dart';''');
590 LibraryElement library = resolve2(source); 590 LibraryElement library = resolve2(source);
591 expect(library, isNotNull); 591 expect(library, isNotNull);
592 FunctionElement main = library.entryPoint; 592 FunctionElement main = library.entryPoint;
593 expect(main, isNotNull); 593 expect(main, isNotNull);
594 expect(main.library, isNot(same(library))); 594 expect(main.library, isNot(same(library)));
595 assertNoErrors(source); 595 await assertNoErrors(source);
596 verify([source]); 596 verify([source]);
597 } 597 }
598 598
599 void test_entryPoint_local() { 599 test_entryPoint_local() async {
600 Source source = addNamedSource( 600 Source source = addNamedSource(
601 "/one.dart", 601 "/one.dart",
602 r''' 602 r'''
603 library one; 603 library one;
604 main() {}'''); 604 main() {}''');
605 LibraryElement library = resolve2(source); 605 LibraryElement library = resolve2(source);
606 expect(library, isNotNull); 606 expect(library, isNotNull);
607 FunctionElement main = library.entryPoint; 607 FunctionElement main = library.entryPoint;
608 expect(main, isNotNull); 608 expect(main, isNotNull);
609 expect(main.library, same(library)); 609 expect(main.library, same(library));
610 assertNoErrors(source); 610 await assertNoErrors(source);
611 verify([source]); 611 verify([source]);
612 } 612 }
613 613
614 void test_entryPoint_none() { 614 test_entryPoint_none() async {
615 Source source = addNamedSource("/one.dart", "library one;"); 615 Source source = addNamedSource("/one.dart", "library one;");
616 LibraryElement library = resolve2(source); 616 LibraryElement library = resolve2(source);
617 expect(library, isNotNull); 617 expect(library, isNotNull);
618 expect(library.entryPoint, isNull); 618 expect(library.entryPoint, isNull);
619 assertNoErrors(source); 619 await assertNoErrors(source);
620 verify([source]); 620 verify([source]);
621 } 621 }
622 622
623 void test_enum_externalLibrary() { 623 test_enum_externalLibrary() async {
624 addNamedSource( 624 addNamedSource(
625 "/my_lib.dart", 625 "/my_lib.dart",
626 r''' 626 r'''
627 library my_lib; 627 library my_lib;
628 enum EEE {A, B, C}'''); 628 enum EEE {A, B, C}''');
629 Source source = addSource(r''' 629 Source source = addSource(r'''
630 import 'my_lib.dart'; 630 import 'my_lib.dart';
631 main() { 631 main() {
632 EEE e = null; 632 EEE e = null;
633 }'''); 633 }''');
634 assertNoErrors(source); 634 await assertNoErrors(source);
635 verify([source]); 635 verify([source]);
636 } 636 }
637 637
638 void test_extractedMethodAsConstant() { 638 test_extractedMethodAsConstant() async {
639 Source source = addSource(r''' 639 Source source = addSource(r'''
640 abstract class Comparable<T> { 640 abstract class Comparable<T> {
641 int compareTo(T other); 641 int compareTo(T other);
642 static int compare(Comparable a, Comparable b) => a.compareTo(b); 642 static int compare(Comparable a, Comparable b) => a.compareTo(b);
643 } 643 }
644 class A { 644 class A {
645 void sort([compare = Comparable.compare]) {} 645 void sort([compare = Comparable.compare]) {}
646 }'''); 646 }''');
647 assertNoErrors(source); 647 await assertNoErrors(source);
648 verify([source]); 648 verify([source]);
649 } 649 }
650 650
651 void test_fieldFormalParameter() { 651 test_fieldFormalParameter() async {
652 Source source = addSource(r''' 652 Source source = addSource(r'''
653 class A { 653 class A {
654 int x; 654 int x;
655 int y; 655 int y;
656 A(this.x) : y = x {} 656 A(this.x) : y = x {}
657 }'''); 657 }''');
658 CompilationUnit unit = 658 CompilationUnit unit =
659 analysisContext2.resolveCompilationUnit2(source, source); 659 analysisContext2.resolveCompilationUnit2(source, source);
660 ClassDeclaration classA = unit.declarations[0]; 660 ClassDeclaration classA = unit.declarations[0];
661 FieldDeclaration field = classA.members[0]; 661 FieldDeclaration field = classA.members[0];
662 ConstructorDeclaration constructor = classA.members[2]; 662 ConstructorDeclaration constructor = classA.members[2];
663 ParameterElement paramElement = 663 ParameterElement paramElement =
664 constructor.parameters.parameters[0].element; 664 constructor.parameters.parameters[0].element;
665 expect(paramElement, new isInstanceOf<FieldFormalParameterElement>()); 665 expect(paramElement, new isInstanceOf<FieldFormalParameterElement>());
666 expect((paramElement as FieldFormalParameterElement).field, 666 expect((paramElement as FieldFormalParameterElement).field,
667 field.fields.variables[0].element); 667 field.fields.variables[0].element);
668 ConstructorFieldInitializer initializer = constructor.initializers[0]; 668 ConstructorFieldInitializer initializer = constructor.initializers[0];
669 SimpleIdentifier identifierX = initializer.expression; 669 SimpleIdentifier identifierX = initializer.expression;
670 expect(identifierX.staticElement, paramElement); 670 expect(identifierX.staticElement, paramElement);
671 671
672 assertNoErrors(source); 672 await assertNoErrors(source);
673 verify([source]); 673 verify([source]);
674 } 674 }
675 675
676 void test_forEachLoops_nonConflicting() { 676 test_forEachLoops_nonConflicting() async {
677 Source source = addSource(r''' 677 Source source = addSource(r'''
678 f() { 678 f() {
679 List list = [1,2,3]; 679 List list = [1,2,3];
680 for (int x in list) {} 680 for (int x in list) {}
681 for (int x in list) {} 681 for (int x in list) {}
682 }'''); 682 }''');
683 assertNoErrors(source); 683 await assertNoErrors(source);
684 verify([source]); 684 verify([source]);
685 } 685 }
686 686
687 void test_forLoops_nonConflicting() { 687 test_forLoops_nonConflicting() async {
688 Source source = addSource(r''' 688 Source source = addSource(r'''
689 f() { 689 f() {
690 for (int i = 0; i < 3; i++) { 690 for (int i = 0; i < 3; i++) {
691 } 691 }
692 for (int i = 0; i < 3; i++) { 692 for (int i = 0; i < 3; i++) {
693 } 693 }
694 }'''); 694 }''');
695 assertNoErrors(source); 695 await assertNoErrors(source);
696 verify([source]); 696 verify([source]);
697 } 697 }
698 698
699 void test_functionTypeAlias() { 699 test_functionTypeAlias() async {
700 Source source = addSource(r''' 700 Source source = addSource(r'''
701 typedef bool P(e); 701 typedef bool P(e);
702 class A { 702 class A {
703 P p; 703 P p;
704 m(e) { 704 m(e) {
705 if (p(e)) {} 705 if (p(e)) {}
706 } 706 }
707 }'''); 707 }''');
708 assertNoErrors(source); 708 await assertNoErrors(source);
709 verify([source]); 709 verify([source]);
710 } 710 }
711 711
712 void test_getter_and_setter_fromMixins_bare_identifier() { 712 test_getter_and_setter_fromMixins_bare_identifier() async {
713 Source source = addSource(''' 713 Source source = addSource('''
714 class B {} 714 class B {}
715 class M1 { 715 class M1 {
716 get x => null; 716 get x => null;
717 set x(value) {} 717 set x(value) {}
718 } 718 }
719 class M2 { 719 class M2 {
720 get x => null; 720 get x => null;
721 set x(value) {} 721 set x(value) {}
722 } 722 }
723 class C extends B with M1, M2 { 723 class C extends B with M1, M2 {
724 void f() { 724 void f() {
725 x += 1; 725 x += 1;
726 } 726 }
727 } 727 }
728 '''); 728 ''');
729 LibraryElement library = resolve2(source); 729 LibraryElement library = resolve2(source);
730 assertNoErrors(source); 730 await assertNoErrors(source);
731 verify([source]); 731 verify([source]);
732 // Verify that both the getter and setter for "x" in C.f() refer to the 732 // Verify that both the getter and setter for "x" in C.f() refer to the
733 // accessors defined in M2. 733 // accessors defined in M2.
734 ClassElement classC = library.definingCompilationUnit.types[3]; 734 ClassElement classC = library.definingCompilationUnit.types[3];
735 MethodDeclaration f = classC.getMethod('f').computeNode(); 735 MethodDeclaration f = classC.getMethod('f').computeNode();
736 BlockFunctionBody body = f.body; 736 BlockFunctionBody body = f.body;
737 ExpressionStatement stmt = body.block.statements[0]; 737 ExpressionStatement stmt = body.block.statements[0];
738 AssignmentExpression assignment = stmt.expression; 738 AssignmentExpression assignment = stmt.expression;
739 SimpleIdentifier leftHandSide = assignment.leftHandSide; 739 SimpleIdentifier leftHandSide = assignment.leftHandSide;
740 expect( 740 expect(
741 resolutionMap 741 resolutionMap
742 .staticElementForIdentifier(leftHandSide) 742 .staticElementForIdentifier(leftHandSide)
743 .enclosingElement 743 .enclosingElement
744 .name, 744 .name,
745 'M2'); 745 'M2');
746 expect(leftHandSide.auxiliaryElements.staticElement.enclosingElement.name, 746 expect(leftHandSide.auxiliaryElements.staticElement.enclosingElement.name,
747 'M2'); 747 'M2');
748 } 748 }
749 749
750 @failingTest 750 @failingTest
751 void test_getter_and_setter_fromMixins_property_access() { 751 test_getter_and_setter_fromMixins_property_access() async {
752 // TODO(paulberry): it appears that auxiliaryElements isn't properly set on 752 // TODO(paulberry): it appears that auxiliaryElements isn't properly set on
753 // a SimpleIdentifier that's inside a property access. This bug should be 753 // a SimpleIdentifier that's inside a property access. This bug should be
754 // fixed. 754 // fixed.
755 Source source = addSource(''' 755 Source source = addSource('''
756 class B {} 756 class B {}
757 class M1 { 757 class M1 {
758 get x => null; 758 get x => null;
759 set x(value) {} 759 set x(value) {}
760 } 760 }
761 class M2 { 761 class M2 {
762 get x => null; 762 get x => null;
763 set x(value) {} 763 set x(value) {}
764 } 764 }
765 class C extends B with M1, M2 {} 765 class C extends B with M1, M2 {}
766 void main() { 766 void main() {
767 new C().x += 1; 767 new C().x += 1;
768 } 768 }
769 '''); 769 ''');
770 LibraryElement library = resolve2(source); 770 LibraryElement library = resolve2(source);
771 assertNoErrors(source); 771 await assertNoErrors(source);
772 verify([source]); 772 verify([source]);
773 // Verify that both the getter and setter for "x" in "new C().x" refer to 773 // Verify that both the getter and setter for "x" in "new C().x" refer to
774 // the accessors defined in M2. 774 // the accessors defined in M2.
775 FunctionDeclaration main = 775 FunctionDeclaration main =
776 library.definingCompilationUnit.functions[0].computeNode(); 776 library.definingCompilationUnit.functions[0].computeNode();
777 BlockFunctionBody body = main.functionExpression.body; 777 BlockFunctionBody body = main.functionExpression.body;
778 ExpressionStatement stmt = body.block.statements[0]; 778 ExpressionStatement stmt = body.block.statements[0];
779 AssignmentExpression assignment = stmt.expression; 779 AssignmentExpression assignment = stmt.expression;
780 PropertyAccess propertyAccess = assignment.leftHandSide; 780 PropertyAccess propertyAccess = assignment.leftHandSide;
781 expect( 781 expect(
782 resolutionMap 782 resolutionMap
783 .staticElementForIdentifier(propertyAccess.propertyName) 783 .staticElementForIdentifier(propertyAccess.propertyName)
784 .enclosingElement 784 .enclosingElement
785 .name, 785 .name,
786 'M2'); 786 'M2');
787 expect( 787 expect(
788 propertyAccess 788 propertyAccess
789 .propertyName.auxiliaryElements.staticElement.enclosingElement.name, 789 .propertyName.auxiliaryElements.staticElement.enclosingElement.name,
790 'M2'); 790 'M2');
791 } 791 }
792 792
793 void test_getter_fromMixins_bare_identifier() { 793 test_getter_fromMixins_bare_identifier() async {
794 Source source = addSource(''' 794 Source source = addSource('''
795 class B {} 795 class B {}
796 class M1 { 796 class M1 {
797 get x => null; 797 get x => null;
798 } 798 }
799 class M2 { 799 class M2 {
800 get x => null; 800 get x => null;
801 } 801 }
802 class C extends B with M1, M2 { 802 class C extends B with M1, M2 {
803 f() { 803 f() {
804 return x; 804 return x;
805 } 805 }
806 } 806 }
807 '''); 807 ''');
808 LibraryElement library = resolve2(source); 808 LibraryElement library = resolve2(source);
809 assertNoErrors(source); 809 await assertNoErrors(source);
810 verify([source]); 810 verify([source]);
811 // Verify that the getter for "x" in C.f() refers to the getter defined in 811 // Verify that the getter for "x" in C.f() refers to the getter defined in
812 // M2. 812 // M2.
813 ClassElement classC = library.definingCompilationUnit.types[3]; 813 ClassElement classC = library.definingCompilationUnit.types[3];
814 MethodDeclaration f = classC.getMethod('f').computeNode(); 814 MethodDeclaration f = classC.getMethod('f').computeNode();
815 BlockFunctionBody body = f.body; 815 BlockFunctionBody body = f.body;
816 ReturnStatement stmt = body.block.statements[0]; 816 ReturnStatement stmt = body.block.statements[0];
817 SimpleIdentifier x = stmt.expression; 817 SimpleIdentifier x = stmt.expression;
818 expect(resolutionMap.staticElementForIdentifier(x).enclosingElement.name, 818 expect(resolutionMap.staticElementForIdentifier(x).enclosingElement.name,
819 'M2'); 819 'M2');
820 } 820 }
821 821
822 void test_getter_fromMixins_property_access() { 822 test_getter_fromMixins_property_access() async {
823 Source source = addSource(''' 823 Source source = addSource('''
824 class B {} 824 class B {}
825 class M1 { 825 class M1 {
826 get x => null; 826 get x => null;
827 } 827 }
828 class M2 { 828 class M2 {
829 get x => null; 829 get x => null;
830 } 830 }
831 class C extends B with M1, M2 {} 831 class C extends B with M1, M2 {}
832 void main() { 832 void main() {
833 var y = new C().x; 833 var y = new C().x;
834 } 834 }
835 '''); 835 ''');
836 LibraryElement library = resolve2(source); 836 LibraryElement library = resolve2(source);
837 assertNoErrors(source); 837 await assertNoErrors(source);
838 verify([source]); 838 verify([source]);
839 // Verify that the getter for "x" in "new C().x" refers to the getter 839 // Verify that the getter for "x" in "new C().x" refers to the getter
840 // defined in M2. 840 // defined in M2.
841 FunctionDeclaration main = 841 FunctionDeclaration main =
842 library.definingCompilationUnit.functions[0].computeNode(); 842 library.definingCompilationUnit.functions[0].computeNode();
843 BlockFunctionBody body = main.functionExpression.body; 843 BlockFunctionBody body = main.functionExpression.body;
844 VariableDeclarationStatement stmt = body.block.statements[0]; 844 VariableDeclarationStatement stmt = body.block.statements[0];
845 PropertyAccess propertyAccess = stmt.variables.variables[0].initializer; 845 PropertyAccess propertyAccess = stmt.variables.variables[0].initializer;
846 expect( 846 expect(
847 resolutionMap 847 resolutionMap
848 .staticElementForIdentifier(propertyAccess.propertyName) 848 .staticElementForIdentifier(propertyAccess.propertyName)
849 .enclosingElement 849 .enclosingElement
850 .name, 850 .name,
851 'M2'); 851 'M2');
852 } 852 }
853 853
854 void test_getterAndSetterWithDifferentTypes() { 854 test_getterAndSetterWithDifferentTypes() async {
855 Source source = addSource(r''' 855 Source source = addSource(r'''
856 class A { 856 class A {
857 int get f => 0; 857 int get f => 0;
858 void set f(String s) {} 858 void set f(String s) {}
859 } 859 }
860 g (A a) { 860 g (A a) {
861 a.f = a.f.toString(); 861 a.f = a.f.toString();
862 }'''); 862 }''');
863 assertErrors( 863 await assertErrors(
864 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); 864 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]);
865 verify([source]); 865 verify([source]);
866 } 866 }
867 867
868 void test_hasReferenceToSuper() { 868 test_hasReferenceToSuper() async {
869 Source source = addSource(r''' 869 Source source = addSource(r'''
870 class A {} 870 class A {}
871 class B {toString() => super.toString();}'''); 871 class B {toString() => super.toString();}''');
872 LibraryElement library = resolve2(source); 872 LibraryElement library = resolve2(source);
873 expect(library, isNotNull); 873 expect(library, isNotNull);
874 CompilationUnitElement unit = library.definingCompilationUnit; 874 CompilationUnitElement unit = library.definingCompilationUnit;
875 expect(unit, isNotNull); 875 expect(unit, isNotNull);
876 List<ClassElement> classes = unit.types; 876 List<ClassElement> classes = unit.types;
877 expect(classes, hasLength(2)); 877 expect(classes, hasLength(2));
878 expect(classes[0].hasReferenceToSuper, isFalse); 878 expect(classes[0].hasReferenceToSuper, isFalse);
879 expect(classes[1].hasReferenceToSuper, isTrue); 879 expect(classes[1].hasReferenceToSuper, isTrue);
880 assertNoErrors(source); 880 await assertNoErrors(source);
881 verify([source]); 881 verify([source]);
882 } 882 }
883 883
884 void test_import_hide() { 884 test_import_hide() async {
885 addNamedSource( 885 addNamedSource(
886 "/lib1.dart", 886 "/lib1.dart",
887 r''' 887 r'''
888 library lib1; 888 library lib1;
889 set foo(value) {} 889 set foo(value) {}
890 class A {}'''); 890 class A {}''');
891 addNamedSource( 891 addNamedSource(
892 "/lib2.dart", 892 "/lib2.dart",
893 r''' 893 r'''
894 library lib2; 894 library lib2;
895 set foo(value) {}'''); 895 set foo(value) {}''');
896 Source source = addNamedSource( 896 Source source = addNamedSource(
897 "/lib3.dart", 897 "/lib3.dart",
898 r''' 898 r'''
899 import 'lib1.dart' hide foo; 899 import 'lib1.dart' hide foo;
900 import 'lib2.dart'; 900 import 'lib2.dart';
901 901
902 main() { 902 main() {
903 foo = 0; 903 foo = 0;
904 } 904 }
905 A a;'''); 905 A a;''');
906 assertNoErrors(source); 906 await assertNoErrors(source);
907 verify([source]); 907 verify([source]);
908 } 908 }
909 909
910 void test_import_prefix() { 910 test_import_prefix() async {
911 addNamedSource( 911 addNamedSource(
912 "/two.dart", 912 "/two.dart",
913 r''' 913 r'''
914 library two; 914 library two;
915 f(int x) { 915 f(int x) {
916 return x * x; 916 return x * x;
917 }'''); 917 }''');
918 Source source = addNamedSource( 918 Source source = addNamedSource(
919 "/one.dart", 919 "/one.dart",
920 r''' 920 r'''
921 library one; 921 library one;
922 import 'two.dart' as _two; 922 import 'two.dart' as _two;
923 main() { 923 main() {
924 _two.f(0); 924 _two.f(0);
925 }'''); 925 }''');
926 assertNoErrors(source); 926 await assertNoErrors(source);
927 verify([source]); 927 verify([source]);
928 } 928 }
929 929
930 void test_import_prefix_doesNotExist() { 930 test_import_prefix_doesNotExist() async {
931 // 931 //
932 // The primary purpose of this test is to ensure that we are only getting a 932 // The primary purpose of this test is to ensure that we are only getting a
933 // single error generated when the only problem is that an imported file 933 // single error generated when the only problem is that an imported file
934 // does not exist. 934 // does not exist.
935 // 935 //
936 Source source = addNamedSource( 936 Source source = addNamedSource(
937 "/a.dart", 937 "/a.dart",
938 r''' 938 r'''
939 import 'missing.dart' as p; 939 import 'missing.dart' as p;
940 int a = p.q + p.r.s; 940 int a = p.q + p.r.s;
941 String b = p.t(a) + p.u(v: 0); 941 String b = p.t(a) + p.u(v: 0);
942 p.T c = new p.T(); 942 p.T c = new p.T();
943 class D<E> extends p.T { 943 class D<E> extends p.T {
944 D(int i) : super(i); 944 D(int i) : super(i);
945 p.U f = new p.V(); 945 p.U f = new p.V();
946 } 946 }
947 class F implements p.T { 947 class F implements p.T {
948 p.T m(p.U u) => null; 948 p.T m(p.U u) => null;
949 } 949 }
950 class G extends Object with p.V {} 950 class G extends Object with p.V {}
951 class H extends D<p.W> { 951 class H extends D<p.W> {
952 H(int i) : super(i); 952 H(int i) : super(i);
953 } 953 }
954 '''); 954 ''');
955 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 955 await assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
956 verify([source]); 956 verify([source]);
957 } 957 }
958 958
959 void test_import_show_doesNotExist() { 959 test_import_show_doesNotExist() async {
960 // 960 //
961 // The primary purpose of this test is to ensure that we are only getting a 961 // The primary purpose of this test is to ensure that we are only getting a
962 // single error generated when the only problem is that an imported file 962 // single error generated when the only problem is that an imported file
963 // does not exist. 963 // does not exist.
964 // 964 //
965 Source source = addNamedSource( 965 Source source = addNamedSource(
966 "/a.dart", 966 "/a.dart",
967 r''' 967 r'''
968 import 'missing.dart' show q, r, t, u, T, U, V, W; 968 import 'missing.dart' show q, r, t, u, T, U, V, W;
969 int a = q + r.s; 969 int a = q + r.s;
970 String b = t(a) + u(v: 0); 970 String b = t(a) + u(v: 0);
971 T c = new T(); 971 T c = new T();
972 class D<E> extends T { 972 class D<E> extends T {
973 D(int i) : super(i); 973 D(int i) : super(i);
974 U f = new V(); 974 U f = new V();
975 } 975 }
976 class F implements T { 976 class F implements T {
977 T m(U u) => null; 977 T m(U u) => null;
978 } 978 }
979 class G extends Object with V {} 979 class G extends Object with V {}
980 class H extends D<W> { 980 class H extends D<W> {
981 H(int i) : super(i); 981 H(int i) : super(i);
982 } 982 }
983 '''); 983 ''');
984 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 984 await assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
985 verify([source]); 985 verify([source]);
986 } 986 }
987 987
988 void test_import_spaceInUri() { 988 test_import_spaceInUri() async {
989 addNamedSource( 989 addNamedSource(
990 "/sub folder/lib.dart", 990 "/sub folder/lib.dart",
991 r''' 991 r'''
992 library lib; 992 library lib;
993 foo() {}'''); 993 foo() {}''');
994 Source source = addNamedSource( 994 Source source = addNamedSource(
995 "/app.dart", 995 "/app.dart",
996 r''' 996 r'''
997 import 'sub folder/lib.dart'; 997 import 'sub folder/lib.dart';
998 998
999 main() { 999 main() {
1000 foo(); 1000 foo();
1001 }'''); 1001 }''');
1002 assertNoErrors(source); 1002 await assertNoErrors(source);
1003 verify([source]); 1003 verify([source]);
1004 } 1004 }
1005 1005
1006 void test_indexExpression_typeParameters() { 1006 test_indexExpression_typeParameters() async {
1007 Source source = addSource(r''' 1007 Source source = addSource(r'''
1008 f() { 1008 f() {
1009 List<int> a; 1009 List<int> a;
1010 a[0]; 1010 a[0];
1011 List<List<int>> b; 1011 List<List<int>> b;
1012 b[0][0]; 1012 b[0][0];
1013 List<List<List<int>>> c; 1013 List<List<List<int>>> c;
1014 c[0][0][0]; 1014 c[0][0][0];
1015 }'''); 1015 }''');
1016 assertNoErrors(source); 1016 await assertNoErrors(source);
1017 verify([source]); 1017 verify([source]);
1018 } 1018 }
1019 1019
1020 void test_indexExpression_typeParameters_invalidAssignmentWarning() { 1020 test_indexExpression_typeParameters_invalidAssignmentWarning() async {
1021 Source source = addSource(r''' 1021 Source source = addSource(r'''
1022 f() { 1022 f() {
1023 List<List<int>> b; 1023 List<List<int>> b;
1024 b[0][0] = 'hi'; 1024 b[0][0] = 'hi';
1025 }'''); 1025 }''');
1026 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); 1026 await assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
1027 verify([source]); 1027 verify([source]);
1028 } 1028 }
1029 1029
1030 void test_indirectOperatorThroughCall() { 1030 test_indirectOperatorThroughCall() async {
1031 Source source = addSource(r''' 1031 Source source = addSource(r'''
1032 class A { 1032 class A {
1033 B call() { return new B(); } 1033 B call() { return new B(); }
1034 } 1034 }
1035 1035
1036 class B { 1036 class B {
1037 int operator [](int i) { return i; } 1037 int operator [](int i) { return i; }
1038 } 1038 }
1039 1039
1040 A f = new A(); 1040 A f = new A();
1041 1041
1042 g(int x) {} 1042 g(int x) {}
1043 1043
1044 main() { 1044 main() {
1045 g(f()[0]); 1045 g(f()[0]);
1046 }'''); 1046 }''');
1047 assertNoErrors(source); 1047 await assertNoErrors(source);
1048 verify([source]); 1048 verify([source]);
1049 } 1049 }
1050 1050
1051 void test_invoke_dynamicThroughGetter() { 1051 test_invoke_dynamicThroughGetter() async {
1052 Source source = addSource(r''' 1052 Source source = addSource(r'''
1053 class A { 1053 class A {
1054 List get X => [() => 0]; 1054 List get X => [() => 0];
1055 m(A a) { 1055 m(A a) {
1056 X.last; 1056 X.last;
1057 } 1057 }
1058 }'''); 1058 }''');
1059 assertNoErrors(source); 1059 await assertNoErrors(source);
1060 verify([source]); 1060 verify([source]);
1061 } 1061 }
1062 1062
1063 void test_isValidMixin_badSuperclass() { 1063 test_isValidMixin_badSuperclass() async {
1064 Source source = addSource(r''' 1064 Source source = addSource(r'''
1065 class A extends B {} 1065 class A extends B {}
1066 class B {} 1066 class B {}
1067 class C = Object with A;'''); 1067 class C = Object with A;''');
1068 LibraryElement library = resolve2(source); 1068 LibraryElement library = resolve2(source);
1069 expect(library, isNotNull); 1069 expect(library, isNotNull);
1070 CompilationUnitElement unit = library.definingCompilationUnit; 1070 CompilationUnitElement unit = library.definingCompilationUnit;
1071 expect(unit, isNotNull); 1071 expect(unit, isNotNull);
1072 ClassElement a = unit.getType('A'); 1072 ClassElement a = unit.getType('A');
1073 expect(a.isValidMixin, isFalse); 1073 expect(a.isValidMixin, isFalse);
1074 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 1074 await assertErrors(
1075 source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
1075 verify([source]); 1076 verify([source]);
1076 } 1077 }
1077 1078
1078 void test_isValidMixin_badSuperclass_withSuperMixins() { 1079 test_isValidMixin_badSuperclass_withSuperMixins() async {
1079 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); 1080 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
1080 Source source = addSource(r''' 1081 Source source = addSource(r'''
1081 class A extends B {} 1082 class A extends B {}
1082 class B {} 1083 class B {}
1083 class C = Object with A;'''); 1084 class C = Object with A;''');
1084 LibraryElement library = resolve2(source); 1085 LibraryElement library = resolve2(source);
1085 expect(library, isNotNull); 1086 expect(library, isNotNull);
1086 CompilationUnitElement unit = library.definingCompilationUnit; 1087 CompilationUnitElement unit = library.definingCompilationUnit;
1087 expect(unit, isNotNull); 1088 expect(unit, isNotNull);
1088 ClassElement a = unit.getType('A'); 1089 ClassElement a = unit.getType('A');
1089 expect(a.isValidMixin, isTrue); 1090 expect(a.isValidMixin, isTrue);
1090 assertNoErrors(source); 1091 await assertNoErrors(source);
1091 verify([source]); 1092 verify([source]);
1092 } 1093 }
1093 1094
1094 void test_isValidMixin_constructor() { 1095 test_isValidMixin_constructor() async {
1095 Source source = addSource(r''' 1096 Source source = addSource(r'''
1096 class A { 1097 class A {
1097 A() {} 1098 A() {}
1098 } 1099 }
1099 class C = Object with A;'''); 1100 class C = Object with A;''');
1100 LibraryElement library = resolve2(source); 1101 LibraryElement library = resolve2(source);
1101 expect(library, isNotNull); 1102 expect(library, isNotNull);
1102 CompilationUnitElement unit = library.definingCompilationUnit; 1103 CompilationUnitElement unit = library.definingCompilationUnit;
1103 expect(unit, isNotNull); 1104 expect(unit, isNotNull);
1104 ClassElement a = unit.getType('A'); 1105 ClassElement a = unit.getType('A');
1105 expect(a.isValidMixin, isFalse); 1106 expect(a.isValidMixin, isFalse);
1106 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); 1107 await assertErrors(
1108 source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
1107 verify([source]); 1109 verify([source]);
1108 } 1110 }
1109 1111
1110 void test_isValidMixin_constructor_withSuperMixins() { 1112 test_isValidMixin_constructor_withSuperMixins() async {
1111 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); 1113 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
1112 Source source = addSource(r''' 1114 Source source = addSource(r'''
1113 class A { 1115 class A {
1114 A() {} 1116 A() {}
1115 } 1117 }
1116 class C = Object with A;'''); 1118 class C = Object with A;''');
1117 LibraryElement library = resolve2(source); 1119 LibraryElement library = resolve2(source);
1118 expect(library, isNotNull); 1120 expect(library, isNotNull);
1119 CompilationUnitElement unit = library.definingCompilationUnit; 1121 CompilationUnitElement unit = library.definingCompilationUnit;
1120 expect(unit, isNotNull); 1122 expect(unit, isNotNull);
1121 ClassElement a = unit.getType('A'); 1123 ClassElement a = unit.getType('A');
1122 expect(a.isValidMixin, isFalse); 1124 expect(a.isValidMixin, isFalse);
1123 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); 1125 await assertErrors(
1126 source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
1124 verify([source]); 1127 verify([source]);
1125 } 1128 }
1126 1129
1127 void test_isValidMixin_factoryConstructor() { 1130 test_isValidMixin_factoryConstructor() async {
1128 Source source = addSource(r''' 1131 Source source = addSource(r'''
1129 class A { 1132 class A {
1130 factory A() => null; 1133 factory A() => null;
1131 } 1134 }
1132 class C = Object with A;'''); 1135 class C = Object with A;''');
1133 LibraryElement library = resolve2(source); 1136 LibraryElement library = resolve2(source);
1134 expect(library, isNotNull); 1137 expect(library, isNotNull);
1135 CompilationUnitElement unit = library.definingCompilationUnit; 1138 CompilationUnitElement unit = library.definingCompilationUnit;
1136 expect(unit, isNotNull); 1139 expect(unit, isNotNull);
1137 ClassElement a = unit.getType('A'); 1140 ClassElement a = unit.getType('A');
1138 expect(a.isValidMixin, isTrue); 1141 expect(a.isValidMixin, isTrue);
1139 assertNoErrors(source); 1142 await assertNoErrors(source);
1140 verify([source]); 1143 verify([source]);
1141 } 1144 }
1142 1145
1143 void test_isValidMixin_factoryConstructor_withSuperMixins() { 1146 test_isValidMixin_factoryConstructor_withSuperMixins() async {
1144 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); 1147 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
1145 Source source = addSource(r''' 1148 Source source = addSource(r'''
1146 class A { 1149 class A {
1147 factory A() => null; 1150 factory A() => null;
1148 } 1151 }
1149 class C = Object with A;'''); 1152 class C = Object with A;''');
1150 LibraryElement library = resolve2(source); 1153 LibraryElement library = resolve2(source);
1151 expect(library, isNotNull); 1154 expect(library, isNotNull);
1152 CompilationUnitElement unit = library.definingCompilationUnit; 1155 CompilationUnitElement unit = library.definingCompilationUnit;
1153 expect(unit, isNotNull); 1156 expect(unit, isNotNull);
1154 ClassElement a = unit.getType('A'); 1157 ClassElement a = unit.getType('A');
1155 expect(a.isValidMixin, isTrue); 1158 expect(a.isValidMixin, isTrue);
1156 assertNoErrors(source); 1159 await assertNoErrors(source);
1157 verify([source]); 1160 verify([source]);
1158 } 1161 }
1159 1162
1160 void test_isValidMixin_super() { 1163 test_isValidMixin_super() async {
1161 Source source = addSource(r''' 1164 Source source = addSource(r'''
1162 class A { 1165 class A {
1163 toString() { 1166 toString() {
1164 return super.toString(); 1167 return super.toString();
1165 } 1168 }
1166 } 1169 }
1167 class C = Object with A;'''); 1170 class C = Object with A;''');
1168 LibraryElement library = resolve2(source); 1171 LibraryElement library = resolve2(source);
1169 expect(library, isNotNull); 1172 expect(library, isNotNull);
1170 CompilationUnitElement unit = library.definingCompilationUnit; 1173 CompilationUnitElement unit = library.definingCompilationUnit;
1171 expect(unit, isNotNull); 1174 expect(unit, isNotNull);
1172 ClassElement a = unit.getType('A'); 1175 ClassElement a = unit.getType('A');
1173 expect(a.isValidMixin, isFalse); 1176 expect(a.isValidMixin, isFalse);
1174 assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]); 1177 await assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]);
1175 verify([source]); 1178 verify([source]);
1176 } 1179 }
1177 1180
1178 void test_isValidMixin_super_withSuperMixins() { 1181 test_isValidMixin_super_withSuperMixins() async {
1179 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); 1182 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
1180 Source source = addSource(r''' 1183 Source source = addSource(r'''
1181 class A { 1184 class A {
1182 toString() { 1185 toString() {
1183 return super.toString(); 1186 return super.toString();
1184 } 1187 }
1185 } 1188 }
1186 class C = Object with A;'''); 1189 class C = Object with A;''');
1187 LibraryElement library = resolve2(source); 1190 LibraryElement library = resolve2(source);
1188 expect(library, isNotNull); 1191 expect(library, isNotNull);
1189 CompilationUnitElement unit = library.definingCompilationUnit; 1192 CompilationUnitElement unit = library.definingCompilationUnit;
1190 expect(unit, isNotNull); 1193 expect(unit, isNotNull);
1191 ClassElement a = unit.getType('A'); 1194 ClassElement a = unit.getType('A');
1192 expect(a.isValidMixin, isTrue); 1195 expect(a.isValidMixin, isTrue);
1193 assertNoErrors(source); 1196 await assertNoErrors(source);
1194 verify([source]); 1197 verify([source]);
1195 } 1198 }
1196 1199
1197 void test_isValidMixin_valid() { 1200 test_isValidMixin_valid() async {
1198 Source source = addSource(''' 1201 Source source = addSource('''
1199 class A {} 1202 class A {}
1200 class C = Object with A;'''); 1203 class C = Object with A;''');
1201 LibraryElement library = resolve2(source); 1204 LibraryElement library = resolve2(source);
1202 expect(library, isNotNull); 1205 expect(library, isNotNull);
1203 CompilationUnitElement unit = library.definingCompilationUnit; 1206 CompilationUnitElement unit = library.definingCompilationUnit;
1204 expect(unit, isNotNull); 1207 expect(unit, isNotNull);
1205 ClassElement a = unit.getType('A'); 1208 ClassElement a = unit.getType('A');
1206 expect(a.isValidMixin, isTrue); 1209 expect(a.isValidMixin, isTrue);
1207 assertNoErrors(source); 1210 await assertNoErrors(source);
1208 verify([source]); 1211 verify([source]);
1209 } 1212 }
1210 1213
1211 void test_isValidMixin_valid_withSuperMixins() { 1214 test_isValidMixin_valid_withSuperMixins() async {
1212 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); 1215 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
1213 Source source = addSource(''' 1216 Source source = addSource('''
1214 class A {} 1217 class A {}
1215 class C = Object with A;'''); 1218 class C = Object with A;''');
1216 LibraryElement library = resolve2(source); 1219 LibraryElement library = resolve2(source);
1217 expect(library, isNotNull); 1220 expect(library, isNotNull);
1218 CompilationUnitElement unit = library.definingCompilationUnit; 1221 CompilationUnitElement unit = library.definingCompilationUnit;
1219 expect(unit, isNotNull); 1222 expect(unit, isNotNull);
1220 ClassElement a = unit.getType('A'); 1223 ClassElement a = unit.getType('A');
1221 expect(a.isValidMixin, isTrue); 1224 expect(a.isValidMixin, isTrue);
1222 assertNoErrors(source); 1225 await assertNoErrors(source);
1223 verify([source]); 1226 verify([source]);
1224 } 1227 }
1225 1228
1226 void test_labels_switch() { 1229 test_labels_switch() async {
1227 Source source = addSource(r''' 1230 Source source = addSource(r'''
1228 void doSwitch(int target) { 1231 void doSwitch(int target) {
1229 switch (target) { 1232 switch (target) {
1230 l0: case 0: 1233 l0: case 0:
1231 continue l1; 1234 continue l1;
1232 l1: case 1: 1235 l1: case 1:
1233 continue l0; 1236 continue l0;
1234 default: 1237 default:
1235 continue l1; 1238 continue l1;
1236 } 1239 }
1237 }'''); 1240 }''');
1238 LibraryElement library = resolve2(source); 1241 LibraryElement library = resolve2(source);
1239 expect(library, isNotNull); 1242 expect(library, isNotNull);
1240 assertNoErrors(source); 1243 await assertNoErrors(source);
1241 verify([source]); 1244 verify([source]);
1242 } 1245 }
1243 1246
1244 void test_localVariable_types_invoked() { 1247 test_localVariable_types_invoked() async {
1245 Source source = addSource(r''' 1248 Source source = addSource(r'''
1246 const A = null; 1249 const A = null;
1247 main() { 1250 main() {
1248 var myVar = (int p) => 'foo'; 1251 var myVar = (int p) => 'foo';
1249 myVar(42); 1252 myVar(42);
1250 }'''); 1253 }''');
1251 LibraryElement library = resolve2(source); 1254 LibraryElement library = resolve2(source);
1252 expect(library, isNotNull); 1255 expect(library, isNotNull);
1253 CompilationUnit unit = 1256 CompilationUnit unit =
1254 analysisContext.resolveCompilationUnit(source, library); 1257 analysisContext.resolveCompilationUnit(source, library);
1255 expect(unit, isNotNull); 1258 expect(unit, isNotNull);
1256 List<bool> found = [false]; 1259 List<bool> found = [false];
1257 List<CaughtException> thrownException = new List<CaughtException>(1); 1260 List<CaughtException> thrownException = new List<CaughtException>(1);
1258 unit.accept(new _SimpleResolverTest_localVariable_types_invoked( 1261 unit.accept(new _SimpleResolverTest_localVariable_types_invoked(
1259 this, found, thrownException)); 1262 this, found, thrownException));
1260 if (thrownException[0] != null) { 1263 if (thrownException[0] != null) {
1261 throw new AnalysisException( 1264 throw new AnalysisException(
1262 "Exception", new CaughtException(thrownException[0], null)); 1265 "Exception", new CaughtException(thrownException[0], null));
1263 } 1266 }
1264 expect(found[0], isTrue); 1267 expect(found[0], isTrue);
1265 } 1268 }
1266 1269
1267 void test_metadata_class() { 1270 test_metadata_class() async {
1268 Source source = addSource(r''' 1271 Source source = addSource(r'''
1269 const A = null; 1272 const A = null;
1270 @A class C<A> {}'''); 1273 @A class C<A> {}''');
1271 LibraryElement library = resolve2(source); 1274 LibraryElement library = resolve2(source);
1272 expect(library, isNotNull); 1275 expect(library, isNotNull);
1273 CompilationUnitElement unitElement = library.definingCompilationUnit; 1276 CompilationUnitElement unitElement = library.definingCompilationUnit;
1274 expect(unitElement, isNotNull); 1277 expect(unitElement, isNotNull);
1275 List<ClassElement> classes = unitElement.types; 1278 List<ClassElement> classes = unitElement.types;
1276 expect(classes, hasLength(1)); 1279 expect(classes, hasLength(1));
1277 List<ElementAnnotation> annotations = classes[0].metadata; 1280 List<ElementAnnotation> annotations = classes[0].metadata;
1278 expect(annotations, hasLength(1)); 1281 expect(annotations, hasLength(1));
1279 assertNoErrors(source); 1282 await assertNoErrors(source);
1280 verify([source]); 1283 verify([source]);
1281 CompilationUnit unit = resolveCompilationUnit(source, library); 1284 CompilationUnit unit = resolveCompilationUnit(source, library);
1282 NodeList<CompilationUnitMember> declarations = unit.declarations; 1285 NodeList<CompilationUnitMember> declarations = unit.declarations;
1283 expect(declarations, hasLength(2)); 1286 expect(declarations, hasLength(2));
1284 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration) 1287 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration)
1285 .variables 1288 .variables
1286 .variables[0] 1289 .variables[0]
1287 .name 1290 .name
1288 .staticElement; 1291 .staticElement;
1289 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, 1292 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement,
1290 PropertyInducingElement, expectedElement); 1293 PropertyInducingElement, expectedElement);
1291 expectedElement = (expectedElement as PropertyInducingElement).getter; 1294 expectedElement = (expectedElement as PropertyInducingElement).getter;
1292 Element actualElement = 1295 Element actualElement =
1293 (declarations[1] as ClassDeclaration).metadata[0].name.staticElement; 1296 (declarations[1] as ClassDeclaration).metadata[0].name.staticElement;
1294 expect(actualElement, same(expectedElement)); 1297 expect(actualElement, same(expectedElement));
1295 } 1298 }
1296 1299
1297 void test_metadata_field() { 1300 test_metadata_field() async {
1298 Source source = addSource(r''' 1301 Source source = addSource(r'''
1299 const A = null; 1302 const A = null;
1300 class C { 1303 class C {
1301 @A int f; 1304 @A int f;
1302 }'''); 1305 }''');
1303 LibraryElement library = resolve2(source); 1306 LibraryElement library = resolve2(source);
1304 expect(library, isNotNull); 1307 expect(library, isNotNull);
1305 CompilationUnitElement unit = library.definingCompilationUnit; 1308 CompilationUnitElement unit = library.definingCompilationUnit;
1306 expect(unit, isNotNull); 1309 expect(unit, isNotNull);
1307 List<ClassElement> classes = unit.types; 1310 List<ClassElement> classes = unit.types;
1308 expect(classes, hasLength(1)); 1311 expect(classes, hasLength(1));
1309 FieldElement field = classes[0].fields[0]; 1312 FieldElement field = classes[0].fields[0];
1310 List<ElementAnnotation> annotations = field.metadata; 1313 List<ElementAnnotation> annotations = field.metadata;
1311 expect(annotations, hasLength(1)); 1314 expect(annotations, hasLength(1));
1312 assertNoErrors(source); 1315 await assertNoErrors(source);
1313 verify([source]); 1316 verify([source]);
1314 } 1317 }
1315 1318
1316 void test_metadata_fieldFormalParameter() { 1319 test_metadata_fieldFormalParameter() async {
1317 Source source = addSource(r''' 1320 Source source = addSource(r'''
1318 const A = null; 1321 const A = null;
1319 class C { 1322 class C {
1320 int f; 1323 int f;
1321 C(@A this.f); 1324 C(@A this.f);
1322 }'''); 1325 }''');
1323 LibraryElement library = resolve2(source); 1326 LibraryElement library = resolve2(source);
1324 expect(library, isNotNull); 1327 expect(library, isNotNull);
1325 CompilationUnitElement unit = library.definingCompilationUnit; 1328 CompilationUnitElement unit = library.definingCompilationUnit;
1326 expect(unit, isNotNull); 1329 expect(unit, isNotNull);
1327 List<ClassElement> classes = unit.types; 1330 List<ClassElement> classes = unit.types;
1328 expect(classes, hasLength(1)); 1331 expect(classes, hasLength(1));
1329 List<ConstructorElement> constructors = classes[0].constructors; 1332 List<ConstructorElement> constructors = classes[0].constructors;
1330 expect(constructors, hasLength(1)); 1333 expect(constructors, hasLength(1));
1331 List<ParameterElement> parameters = constructors[0].parameters; 1334 List<ParameterElement> parameters = constructors[0].parameters;
1332 expect(parameters, hasLength(1)); 1335 expect(parameters, hasLength(1));
1333 List<ElementAnnotation> annotations = parameters[0].metadata; 1336 List<ElementAnnotation> annotations = parameters[0].metadata;
1334 expect(annotations, hasLength(1)); 1337 expect(annotations, hasLength(1));
1335 assertNoErrors(source); 1338 await assertNoErrors(source);
1336 verify([source]); 1339 verify([source]);
1337 } 1340 }
1338 1341
1339 void test_metadata_function() { 1342 test_metadata_function() async {
1340 Source source = addSource(r''' 1343 Source source = addSource(r'''
1341 const A = null; 1344 const A = null;
1342 @A f() {}'''); 1345 @A f() {}''');
1343 LibraryElement library = resolve2(source); 1346 LibraryElement library = resolve2(source);
1344 expect(library, isNotNull); 1347 expect(library, isNotNull);
1345 CompilationUnitElement unit = library.definingCompilationUnit; 1348 CompilationUnitElement unit = library.definingCompilationUnit;
1346 expect(unit, isNotNull); 1349 expect(unit, isNotNull);
1347 List<FunctionElement> functions = unit.functions; 1350 List<FunctionElement> functions = unit.functions;
1348 expect(functions, hasLength(1)); 1351 expect(functions, hasLength(1));
1349 List<ElementAnnotation> annotations = functions[0].metadata; 1352 List<ElementAnnotation> annotations = functions[0].metadata;
1350 expect(annotations, hasLength(1)); 1353 expect(annotations, hasLength(1));
1351 assertNoErrors(source); 1354 await assertNoErrors(source);
1352 verify([source]); 1355 verify([source]);
1353 } 1356 }
1354 1357
1355 void test_metadata_functionTypedParameter() { 1358 test_metadata_functionTypedParameter() async {
1356 Source source = addSource(r''' 1359 Source source = addSource(r'''
1357 const A = null; 1360 const A = null;
1358 f(@A int p(int x)) {}'''); 1361 f(@A int p(int x)) {}''');
1359 LibraryElement library = resolve2(source); 1362 LibraryElement library = resolve2(source);
1360 expect(library, isNotNull); 1363 expect(library, isNotNull);
1361 CompilationUnitElement unit = library.definingCompilationUnit; 1364 CompilationUnitElement unit = library.definingCompilationUnit;
1362 expect(unit, isNotNull); 1365 expect(unit, isNotNull);
1363 List<FunctionElement> functions = unit.functions; 1366 List<FunctionElement> functions = unit.functions;
1364 expect(functions, hasLength(1)); 1367 expect(functions, hasLength(1));
1365 List<ParameterElement> parameters = functions[0].parameters; 1368 List<ParameterElement> parameters = functions[0].parameters;
1366 expect(parameters, hasLength(1)); 1369 expect(parameters, hasLength(1));
1367 List<ElementAnnotation> annotations1 = parameters[0].metadata; 1370 List<ElementAnnotation> annotations1 = parameters[0].metadata;
1368 expect(annotations1, hasLength(1)); 1371 expect(annotations1, hasLength(1));
1369 assertNoErrors(source); 1372 await assertNoErrors(source);
1370 verify([source]); 1373 verify([source]);
1371 } 1374 }
1372 1375
1373 void test_metadata_libraryDirective() { 1376 test_metadata_libraryDirective() async {
1374 Source source = addSource(r''' 1377 Source source = addSource(r'''
1375 @A library lib; 1378 @A library lib;
1376 const A = null;'''); 1379 const A = null;''');
1377 LibraryElement library = resolve2(source); 1380 LibraryElement library = resolve2(source);
1378 expect(library, isNotNull); 1381 expect(library, isNotNull);
1379 List<ElementAnnotation> annotations = library.metadata; 1382 List<ElementAnnotation> annotations = library.metadata;
1380 expect(annotations, hasLength(1)); 1383 expect(annotations, hasLength(1));
1381 assertNoErrors(source); 1384 await assertNoErrors(source);
1382 verify([source]); 1385 verify([source]);
1383 } 1386 }
1384 1387
1385 void test_metadata_method() { 1388 test_metadata_method() async {
1386 Source source = addSource(r''' 1389 Source source = addSource(r'''
1387 const A = null; 1390 const A = null;
1388 class C { 1391 class C {
1389 @A void m() {} 1392 @A void m() {}
1390 }'''); 1393 }''');
1391 LibraryElement library = resolve2(source); 1394 LibraryElement library = resolve2(source);
1392 expect(library, isNotNull); 1395 expect(library, isNotNull);
1393 CompilationUnitElement unit = library.definingCompilationUnit; 1396 CompilationUnitElement unit = library.definingCompilationUnit;
1394 expect(unit, isNotNull); 1397 expect(unit, isNotNull);
1395 List<ClassElement> classes = unit.types; 1398 List<ClassElement> classes = unit.types;
1396 expect(classes, hasLength(1)); 1399 expect(classes, hasLength(1));
1397 MethodElement method = classes[0].methods[0]; 1400 MethodElement method = classes[0].methods[0];
1398 List<ElementAnnotation> annotations = method.metadata; 1401 List<ElementAnnotation> annotations = method.metadata;
1399 expect(annotations, hasLength(1)); 1402 expect(annotations, hasLength(1));
1400 assertNoErrors(source); 1403 await assertNoErrors(source);
1401 verify([source]); 1404 verify([source]);
1402 } 1405 }
1403 1406
1404 void test_metadata_namedParameter() { 1407 test_metadata_namedParameter() async {
1405 Source source = addSource(r''' 1408 Source source = addSource(r'''
1406 const A = null; 1409 const A = null;
1407 f({@A int p : 0}) {}'''); 1410 f({@A int p : 0}) {}''');
1408 LibraryElement library = resolve2(source); 1411 LibraryElement library = resolve2(source);
1409 expect(library, isNotNull); 1412 expect(library, isNotNull);
1410 CompilationUnitElement unit = library.definingCompilationUnit; 1413 CompilationUnitElement unit = library.definingCompilationUnit;
1411 expect(unit, isNotNull); 1414 expect(unit, isNotNull);
1412 List<FunctionElement> functions = unit.functions; 1415 List<FunctionElement> functions = unit.functions;
1413 expect(functions, hasLength(1)); 1416 expect(functions, hasLength(1));
1414 List<ParameterElement> parameters = functions[0].parameters; 1417 List<ParameterElement> parameters = functions[0].parameters;
1415 expect(parameters, hasLength(1)); 1418 expect(parameters, hasLength(1));
1416 List<ElementAnnotation> annotations1 = parameters[0].metadata; 1419 List<ElementAnnotation> annotations1 = parameters[0].metadata;
1417 expect(annotations1, hasLength(1)); 1420 expect(annotations1, hasLength(1));
1418 assertNoErrors(source); 1421 await assertNoErrors(source);
1419 verify([source]); 1422 verify([source]);
1420 } 1423 }
1421 1424
1422 void test_metadata_positionalParameter() { 1425 test_metadata_positionalParameter() async {
1423 Source source = addSource(r''' 1426 Source source = addSource(r'''
1424 const A = null; 1427 const A = null;
1425 f([@A int p = 0]) {}'''); 1428 f([@A int p = 0]) {}''');
1426 LibraryElement library = resolve2(source); 1429 LibraryElement library = resolve2(source);
1427 expect(library, isNotNull); 1430 expect(library, isNotNull);
1428 CompilationUnitElement unit = library.definingCompilationUnit; 1431 CompilationUnitElement unit = library.definingCompilationUnit;
1429 expect(unit, isNotNull); 1432 expect(unit, isNotNull);
1430 List<FunctionElement> functions = unit.functions; 1433 List<FunctionElement> functions = unit.functions;
1431 expect(functions, hasLength(1)); 1434 expect(functions, hasLength(1));
1432 List<ParameterElement> parameters = functions[0].parameters; 1435 List<ParameterElement> parameters = functions[0].parameters;
1433 expect(parameters, hasLength(1)); 1436 expect(parameters, hasLength(1));
1434 List<ElementAnnotation> annotations1 = parameters[0].metadata; 1437 List<ElementAnnotation> annotations1 = parameters[0].metadata;
1435 expect(annotations1, hasLength(1)); 1438 expect(annotations1, hasLength(1));
1436 assertNoErrors(source); 1439 await assertNoErrors(source);
1437 verify([source]); 1440 verify([source]);
1438 } 1441 }
1439 1442
1440 void test_metadata_simpleParameter() { 1443 test_metadata_simpleParameter() async {
1441 Source source = addSource(r''' 1444 Source source = addSource(r'''
1442 const A = null; 1445 const A = null;
1443 f(@A p1, @A int p2) {}'''); 1446 f(@A p1, @A int p2) {}''');
1444 LibraryElement library = resolve2(source); 1447 LibraryElement library = resolve2(source);
1445 expect(library, isNotNull); 1448 expect(library, isNotNull);
1446 CompilationUnitElement unit = library.definingCompilationUnit; 1449 CompilationUnitElement unit = library.definingCompilationUnit;
1447 expect(unit, isNotNull); 1450 expect(unit, isNotNull);
1448 List<FunctionElement> functions = unit.functions; 1451 List<FunctionElement> functions = unit.functions;
1449 expect(functions, hasLength(1)); 1452 expect(functions, hasLength(1));
1450 List<ParameterElement> parameters = functions[0].parameters; 1453 List<ParameterElement> parameters = functions[0].parameters;
1451 expect(parameters, hasLength(2)); 1454 expect(parameters, hasLength(2));
1452 List<ElementAnnotation> annotations1 = parameters[0].metadata; 1455 List<ElementAnnotation> annotations1 = parameters[0].metadata;
1453 expect(annotations1, hasLength(1)); 1456 expect(annotations1, hasLength(1));
1454 List<ElementAnnotation> annotations2 = parameters[1].metadata; 1457 List<ElementAnnotation> annotations2 = parameters[1].metadata;
1455 expect(annotations2, hasLength(1)); 1458 expect(annotations2, hasLength(1));
1456 assertNoErrors(source); 1459 await assertNoErrors(source);
1457 verify([source]); 1460 verify([source]);
1458 } 1461 }
1459 1462
1460 void test_metadata_typedef() { 1463 test_metadata_typedef() async {
1461 Source source = addSource(r''' 1464 Source source = addSource(r'''
1462 const A = null; 1465 const A = null;
1463 @A typedef F<A>();'''); 1466 @A typedef F<A>();''');
1464 LibraryElement library = resolve2(source); 1467 LibraryElement library = resolve2(source);
1465 expect(library, isNotNull); 1468 expect(library, isNotNull);
1466 CompilationUnitElement unitElement = library.definingCompilationUnit; 1469 CompilationUnitElement unitElement = library.definingCompilationUnit;
1467 expect(unitElement, isNotNull); 1470 expect(unitElement, isNotNull);
1468 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; 1471 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases;
1469 expect(aliases, hasLength(1)); 1472 expect(aliases, hasLength(1));
1470 List<ElementAnnotation> annotations = aliases[0].metadata; 1473 List<ElementAnnotation> annotations = aliases[0].metadata;
1471 expect(annotations, hasLength(1)); 1474 expect(annotations, hasLength(1));
1472 assertNoErrors(source); 1475 await assertNoErrors(source);
1473 verify([source]); 1476 verify([source]);
1474 CompilationUnit unit = resolveCompilationUnit(source, library); 1477 CompilationUnit unit = resolveCompilationUnit(source, library);
1475 NodeList<CompilationUnitMember> declarations = unit.declarations; 1478 NodeList<CompilationUnitMember> declarations = unit.declarations;
1476 expect(declarations, hasLength(2)); 1479 expect(declarations, hasLength(2));
1477 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration) 1480 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration)
1478 .variables 1481 .variables
1479 .variables[0] 1482 .variables[0]
1480 .name 1483 .name
1481 .staticElement; 1484 .staticElement;
1482 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, 1485 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement,
1483 PropertyInducingElement, expectedElement); 1486 PropertyInducingElement, expectedElement);
1484 expectedElement = (expectedElement as PropertyInducingElement).getter; 1487 expectedElement = (expectedElement as PropertyInducingElement).getter;
1485 Element actualElement = 1488 Element actualElement =
1486 (declarations[1] as FunctionTypeAlias).metadata[0].name.staticElement; 1489 (declarations[1] as FunctionTypeAlias).metadata[0].name.staticElement;
1487 expect(actualElement, same(expectedElement)); 1490 expect(actualElement, same(expectedElement));
1488 } 1491 }
1489 1492
1490 void test_method_fromMixin() { 1493 test_method_fromMixin() async {
1491 Source source = addSource(r''' 1494 Source source = addSource(r'''
1492 class B { 1495 class B {
1493 bar() => 1; 1496 bar() => 1;
1494 } 1497 }
1495 class A { 1498 class A {
1496 foo() => 2; 1499 foo() => 2;
1497 } 1500 }
1498 1501
1499 class C extends B with A { 1502 class C extends B with A {
1500 bar() => super.bar(); 1503 bar() => super.bar();
1501 foo() => super.foo(); 1504 foo() => super.foo();
1502 }'''); 1505 }''');
1503 assertNoErrors(source); 1506 await assertNoErrors(source);
1504 verify([source]); 1507 verify([source]);
1505 } 1508 }
1506 1509
1507 void test_method_fromMixins() { 1510 test_method_fromMixins() async {
1508 Source source = addSource(''' 1511 Source source = addSource('''
1509 class B {} 1512 class B {}
1510 class M1 { 1513 class M1 {
1511 void f() {} 1514 void f() {}
1512 } 1515 }
1513 class M2 { 1516 class M2 {
1514 void f() {} 1517 void f() {}
1515 } 1518 }
1516 class C extends B with M1, M2 {} 1519 class C extends B with M1, M2 {}
1517 void main() { 1520 void main() {
1518 new C().f(); 1521 new C().f();
1519 } 1522 }
1520 '''); 1523 ''');
1521 LibraryElement library = resolve2(source); 1524 LibraryElement library = resolve2(source);
1522 assertNoErrors(source); 1525 await assertNoErrors(source);
1523 verify([source]); 1526 verify([source]);
1524 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2. 1527 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2.
1525 FunctionDeclaration main = 1528 FunctionDeclaration main =
1526 library.definingCompilationUnit.functions[0].computeNode(); 1529 library.definingCompilationUnit.functions[0].computeNode();
1527 BlockFunctionBody body = main.functionExpression.body; 1530 BlockFunctionBody body = main.functionExpression.body;
1528 ExpressionStatement stmt = body.block.statements[0]; 1531 ExpressionStatement stmt = body.block.statements[0];
1529 MethodInvocation expr = stmt.expression; 1532 MethodInvocation expr = stmt.expression;
1530 expect( 1533 expect(
1531 resolutionMap 1534 resolutionMap
1532 .staticElementForIdentifier(expr.methodName) 1535 .staticElementForIdentifier(expr.methodName)
1533 .enclosingElement 1536 .enclosingElement
1534 .name, 1537 .name,
1535 'M2'); 1538 'M2');
1536 } 1539 }
1537 1540
1538 void test_method_fromMixins_bare_identifier() { 1541 test_method_fromMixins_bare_identifier() async {
1539 Source source = addSource(''' 1542 Source source = addSource('''
1540 class B {} 1543 class B {}
1541 class M1 { 1544 class M1 {
1542 void f() {} 1545 void f() {}
1543 } 1546 }
1544 class M2 { 1547 class M2 {
1545 void f() {} 1548 void f() {}
1546 } 1549 }
1547 class C extends B with M1, M2 { 1550 class C extends B with M1, M2 {
1548 void g() { 1551 void g() {
1549 f(); 1552 f();
1550 } 1553 }
1551 } 1554 }
1552 '''); 1555 ''');
1553 LibraryElement library = resolve2(source); 1556 LibraryElement library = resolve2(source);
1554 assertNoErrors(source); 1557 await assertNoErrors(source);
1555 verify([source]); 1558 verify([source]);
1556 // Verify that the call to f() in C.g() refers to the method defined in M2. 1559 // Verify that the call to f() in C.g() refers to the method defined in M2.
1557 ClassElement classC = library.definingCompilationUnit.types[3]; 1560 ClassElement classC = library.definingCompilationUnit.types[3];
1558 MethodDeclaration g = classC.getMethod('g').computeNode(); 1561 MethodDeclaration g = classC.getMethod('g').computeNode();
1559 BlockFunctionBody body = g.body; 1562 BlockFunctionBody body = g.body;
1560 ExpressionStatement stmt = body.block.statements[0]; 1563 ExpressionStatement stmt = body.block.statements[0];
1561 MethodInvocation invocation = stmt.expression; 1564 MethodInvocation invocation = stmt.expression;
1562 SimpleIdentifier methodName = invocation.methodName; 1565 SimpleIdentifier methodName = invocation.methodName;
1563 expect( 1566 expect(
1564 resolutionMap 1567 resolutionMap
1565 .staticElementForIdentifier(methodName) 1568 .staticElementForIdentifier(methodName)
1566 .enclosingElement 1569 .enclosingElement
1567 .name, 1570 .name,
1568 'M2'); 1571 'M2');
1569 } 1572 }
1570 1573
1571 void test_method_fromMixins_invked_from_outside_class() { 1574 test_method_fromMixins_invked_from_outside_class() async {
1572 Source source = addSource(''' 1575 Source source = addSource('''
1573 class B {} 1576 class B {}
1574 class M1 { 1577 class M1 {
1575 void f() {} 1578 void f() {}
1576 } 1579 }
1577 class M2 { 1580 class M2 {
1578 void f() {} 1581 void f() {}
1579 } 1582 }
1580 class C extends B with M1, M2 {} 1583 class C extends B with M1, M2 {}
1581 void main() { 1584 void main() {
1582 new C().f(); 1585 new C().f();
1583 } 1586 }
1584 '''); 1587 ''');
1585 LibraryElement library = resolve2(source); 1588 LibraryElement library = resolve2(source);
1586 assertNoErrors(source); 1589 await assertNoErrors(source);
1587 verify([source]); 1590 verify([source]);
1588 // Verify that the call to f() in "new C().f()" refers to the method 1591 // Verify that the call to f() in "new C().f()" refers to the method
1589 // defined in M2. 1592 // defined in M2.
1590 FunctionDeclaration main = 1593 FunctionDeclaration main =
1591 library.definingCompilationUnit.functions[0].computeNode(); 1594 library.definingCompilationUnit.functions[0].computeNode();
1592 BlockFunctionBody body = main.functionExpression.body; 1595 BlockFunctionBody body = main.functionExpression.body;
1593 ExpressionStatement stmt = body.block.statements[0]; 1596 ExpressionStatement stmt = body.block.statements[0];
1594 MethodInvocation invocation = stmt.expression; 1597 MethodInvocation invocation = stmt.expression;
1595 expect( 1598 expect(
1596 resolutionMap 1599 resolutionMap
1597 .staticElementForIdentifier(invocation.methodName) 1600 .staticElementForIdentifier(invocation.methodName)
1598 .enclosingElement 1601 .enclosingElement
1599 .name, 1602 .name,
1600 'M2'); 1603 'M2');
1601 } 1604 }
1602 1605
1603 void test_method_fromSuperclassMixin() { 1606 test_method_fromSuperclassMixin() async {
1604 Source source = addSource(r''' 1607 Source source = addSource(r'''
1605 class A { 1608 class A {
1606 void m1() {} 1609 void m1() {}
1607 } 1610 }
1608 class B extends Object with A { 1611 class B extends Object with A {
1609 } 1612 }
1610 class C extends B { 1613 class C extends B {
1611 } 1614 }
1612 f(C c) { 1615 f(C c) {
1613 c.m1(); 1616 c.m1();
1614 }'''); 1617 }''');
1615 assertNoErrors(source); 1618 await assertNoErrors(source);
1616 verify([source]); 1619 verify([source]);
1617 } 1620 }
1618 1621
1619 void test_methodCascades() { 1622 test_methodCascades() async {
1620 Source source = addSource(r''' 1623 Source source = addSource(r'''
1621 class A { 1624 class A {
1622 void m1() {} 1625 void m1() {}
1623 void m2() {} 1626 void m2() {}
1624 void m() { 1627 void m() {
1625 A a = new A(); 1628 A a = new A();
1626 a..m1() 1629 a..m1()
1627 ..m2(); 1630 ..m2();
1628 } 1631 }
1629 }'''); 1632 }''');
1630 assertNoErrors(source); 1633 await assertNoErrors(source);
1631 verify([source]); 1634 verify([source]);
1632 } 1635 }
1633 1636
1634 void test_methodCascades_withSetter() { 1637 test_methodCascades_withSetter() async {
1635 Source source = addSource(r''' 1638 Source source = addSource(r'''
1636 class A { 1639 class A {
1637 String name; 1640 String name;
1638 void m1() {} 1641 void m1() {}
1639 void m2() {} 1642 void m2() {}
1640 void m() { 1643 void m() {
1641 A a = new A(); 1644 A a = new A();
1642 a..m1() 1645 a..m1()
1643 ..name = 'name' 1646 ..name = 'name'
1644 ..m2(); 1647 ..m2();
1645 } 1648 }
1646 }'''); 1649 }''');
1647 // failing with error code: INVOCATION_OF_NON_FUNCTION 1650 // failing with error code: INVOCATION_OF_NON_FUNCTION
1648 assertNoErrors(source); 1651 await assertNoErrors(source);
1649 verify([source]); 1652 verify([source]);
1650 } 1653 }
1651 1654
1652 void test_resolveAgainstNull() { 1655 test_resolveAgainstNull() async {
1653 Source source = addSource(r''' 1656 Source source = addSource(r'''
1654 f(var p) { 1657 f(var p) {
1655 return null == p; 1658 return null == p;
1656 }'''); 1659 }''');
1657 assertNoErrors(source); 1660 await assertNoErrors(source);
1658 } 1661 }
1659 1662
1660 void test_setter_fromMixins_bare_identifier() { 1663 test_setter_fromMixins_bare_identifier() async {
1661 Source source = addSource(''' 1664 Source source = addSource('''
1662 class B {} 1665 class B {}
1663 class M1 { 1666 class M1 {
1664 set x(value) {} 1667 set x(value) {}
1665 } 1668 }
1666 class M2 { 1669 class M2 {
1667 set x(value) {} 1670 set x(value) {}
1668 } 1671 }
1669 class C extends B with M1, M2 { 1672 class C extends B with M1, M2 {
1670 void f() { 1673 void f() {
1671 x = 1; 1674 x = 1;
1672 } 1675 }
1673 } 1676 }
1674 '''); 1677 ''');
1675 LibraryElement library = resolve2(source); 1678 LibraryElement library = resolve2(source);
1676 assertNoErrors(source); 1679 await assertNoErrors(source);
1677 verify([source]); 1680 verify([source]);
1678 // Verify that the setter for "x" in C.f() refers to the setter defined in 1681 // Verify that the setter for "x" in C.f() refers to the setter defined in
1679 // M2. 1682 // M2.
1680 ClassElement classC = library.definingCompilationUnit.types[3]; 1683 ClassElement classC = library.definingCompilationUnit.types[3];
1681 MethodDeclaration f = classC.getMethod('f').computeNode(); 1684 MethodDeclaration f = classC.getMethod('f').computeNode();
1682 BlockFunctionBody body = f.body; 1685 BlockFunctionBody body = f.body;
1683 ExpressionStatement stmt = body.block.statements[0]; 1686 ExpressionStatement stmt = body.block.statements[0];
1684 AssignmentExpression assignment = stmt.expression; 1687 AssignmentExpression assignment = stmt.expression;
1685 SimpleIdentifier leftHandSide = assignment.leftHandSide; 1688 SimpleIdentifier leftHandSide = assignment.leftHandSide;
1686 expect( 1689 expect(
1687 resolutionMap 1690 resolutionMap
1688 .staticElementForIdentifier(leftHandSide) 1691 .staticElementForIdentifier(leftHandSide)
1689 .enclosingElement 1692 .enclosingElement
1690 .name, 1693 .name,
1691 'M2'); 1694 'M2');
1692 } 1695 }
1693 1696
1694 void test_setter_fromMixins_property_access() { 1697 test_setter_fromMixins_property_access() async {
1695 Source source = addSource(''' 1698 Source source = addSource('''
1696 class B {} 1699 class B {}
1697 class M1 { 1700 class M1 {
1698 set x(value) {} 1701 set x(value) {}
1699 } 1702 }
1700 class M2 { 1703 class M2 {
1701 set x(value) {} 1704 set x(value) {}
1702 } 1705 }
1703 class C extends B with M1, M2 {} 1706 class C extends B with M1, M2 {}
1704 void main() { 1707 void main() {
1705 new C().x = 1; 1708 new C().x = 1;
1706 } 1709 }
1707 '''); 1710 ''');
1708 LibraryElement library = resolve2(source); 1711 LibraryElement library = resolve2(source);
1709 assertNoErrors(source); 1712 await assertNoErrors(source);
1710 verify([source]); 1713 verify([source]);
1711 // Verify that the setter for "x" in "new C().x" refers to the setter 1714 // Verify that the setter for "x" in "new C().x" refers to the setter
1712 // defined in M2. 1715 // defined in M2.
1713 FunctionDeclaration main = 1716 FunctionDeclaration main =
1714 library.definingCompilationUnit.functions[0].computeNode(); 1717 library.definingCompilationUnit.functions[0].computeNode();
1715 BlockFunctionBody body = main.functionExpression.body; 1718 BlockFunctionBody body = main.functionExpression.body;
1716 ExpressionStatement stmt = body.block.statements[0]; 1719 ExpressionStatement stmt = body.block.statements[0];
1717 AssignmentExpression assignment = stmt.expression; 1720 AssignmentExpression assignment = stmt.expression;
1718 PropertyAccess propertyAccess = assignment.leftHandSide; 1721 PropertyAccess propertyAccess = assignment.leftHandSide;
1719 expect( 1722 expect(
1720 resolutionMap 1723 resolutionMap
1721 .staticElementForIdentifier(propertyAccess.propertyName) 1724 .staticElementForIdentifier(propertyAccess.propertyName)
1722 .enclosingElement 1725 .enclosingElement
1723 .name, 1726 .name,
1724 'M2'); 1727 'M2');
1725 } 1728 }
1726 1729
1727 void test_setter_inherited() { 1730 test_setter_inherited() async {
1728 Source source = addSource(r''' 1731 Source source = addSource(r'''
1729 class A { 1732 class A {
1730 int get x => 0; 1733 int get x => 0;
1731 set x(int p) {} 1734 set x(int p) {}
1732 } 1735 }
1733 class B extends A { 1736 class B extends A {
1734 int get x => super.x == null ? 0 : super.x; 1737 int get x => super.x == null ? 0 : super.x;
1735 int f() => x = 1; 1738 int f() => x = 1;
1736 }'''); 1739 }''');
1737 assertNoErrors(source); 1740 await assertNoErrors(source);
1738 verify([source]); 1741 verify([source]);
1739 } 1742 }
1740 1743
1741 void test_setter_static() { 1744 test_setter_static() async {
1742 Source source = addSource(r''' 1745 Source source = addSource(r'''
1743 set s(x) { 1746 set s(x) {
1744 } 1747 }
1745 1748
1746 main() { 1749 main() {
1747 s = 123; 1750 s = 123;
1748 }'''); 1751 }''');
1749 assertNoErrors(source); 1752 await assertNoErrors(source);
1750 verify([source]); 1753 verify([source]);
1751 } 1754 }
1752 1755
1753 @failingTest 1756 @failingTest
1754 void test_staticInvocation() { 1757 test_staticInvocation() async {
1755 Source source = addSource(r''' 1758 Source source = addSource(r'''
1756 class A { 1759 class A {
1757 static int get g => (a,b) => 0; 1760 static int get g => (a,b) => 0;
1758 } 1761 }
1759 class B { 1762 class B {
1760 f() { 1763 f() {
1761 A.g(1,0); 1764 A.g(1,0);
1762 } 1765 }
1763 }'''); 1766 }''');
1764 assertNoErrors(source); 1767 await assertNoErrors(source);
1765 verify([source]); 1768 verify([source]);
1766 } 1769 }
1767 1770
1768 /** 1771 /**
1769 * Resolve the given source and verify that the arguments in a specific method invocation were 1772 * Resolve the given source and verify that the arguments in a specific method invocation were
1770 * correctly resolved. 1773 * correctly resolved.
1771 * 1774 *
1772 * The source is expected to be source for a compilation unit, the first decla ration is expected 1775 * The source is expected to be source for a compilation unit, the first decla ration is expected
1773 * to be a class, the first member of which is expected to be a method with a block body, and the 1776 * to be a class, the first member of which is expected to be a method with a block body, and the
1774 * first statement in the body is expected to be an expression statement whose expression is a 1777 * first statement in the body is expected to be an expression statement whose expression is a
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 // check propagated type 1842 // check propagated type
1840 FunctionType propagatedType = node.propagatedType as FunctionType; 1843 FunctionType propagatedType = node.propagatedType as FunctionType;
1841 expect(propagatedType.returnType, test.typeProvider.stringType); 1844 expect(propagatedType.returnType, test.typeProvider.stringType);
1842 } on AnalysisException catch (e, stackTrace) { 1845 } on AnalysisException catch (e, stackTrace) {
1843 thrownException[0] = new CaughtException(e, stackTrace); 1846 thrownException[0] = new CaughtException(e, stackTrace);
1844 } 1847 }
1845 } 1848 }
1846 return null; 1849 return null;
1847 } 1850 }
1848 } 1851 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698