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

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

Issue 2626653002: Remove computeLibrarySourceErrors(). (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.generated.static_warning_code_test; 5 library analyzer.test.generated.static_warning_code_test;
6 6
7 import 'package:analyzer/error/error.dart'; 7 import 'package:analyzer/error/error.dart';
8 import 'package:analyzer/src/error/codes.dart'; 8 import 'package:analyzer/src/error/codes.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/source_io.dart'; 10 import 'package:analyzer/src/generated/source_io.dart';
(...skipping 13 matching lines...) Expand all
24 void fail_argumentTypeNotAssignable_tearOff_required() { 24 void fail_argumentTypeNotAssignable_tearOff_required() {
25 Source source = addSource(r''' 25 Source source = addSource(r'''
26 class C { 26 class C {
27 Object/*=T*/ f/*<T>*/(Object/*=T*/ x) => x; 27 Object/*=T*/ f/*<T>*/(Object/*=T*/ x) => x;
28 } 28 }
29 g(C c) { 29 g(C c) {
30 var h = c.f/*<int>*/; 30 var h = c.f/*<int>*/;
31 print(h('s')); 31 print(h('s'));
32 } 32 }
33 '''); 33 ''');
34 computeLibrarySourceErrors(source);
35 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 34 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
36 verify([source]); 35 verify([source]);
37 } 36 }
38 37
39 void fail_undefinedGetter() { 38 void fail_undefinedGetter() {
40 Source source = addSource(r''' 39 Source source = addSource(r'''
41 '''); 40 ''');
42 computeLibrarySourceErrors(source);
43 assertErrors(source, [StaticWarningCode.UNDEFINED_GETTER]); 41 assertErrors(source, [StaticWarningCode.UNDEFINED_GETTER]);
44 verify([source]); 42 verify([source]);
45 } 43 }
46 44
47 void fail_undefinedIdentifier_commentReference() { 45 void fail_undefinedIdentifier_commentReference() {
48 Source source = addSource(r''' 46 Source source = addSource(r'''
49 /** [m] xxx [new B.c] */ 47 /** [m] xxx [new B.c] */
50 class A { 48 class A {
51 }'''); 49 }''');
52 computeLibrarySourceErrors(source);
53 assertErrors(source, [ 50 assertErrors(source, [
54 StaticWarningCode.UNDEFINED_IDENTIFIER, 51 StaticWarningCode.UNDEFINED_IDENTIFIER,
55 StaticWarningCode.UNDEFINED_IDENTIFIER 52 StaticWarningCode.UNDEFINED_IDENTIFIER
56 ]); 53 ]);
57 } 54 }
58 55
59 void fail_undefinedSetter() { 56 void fail_undefinedSetter() {
60 Source source = addSource(r''' 57 Source source = addSource(r'''
61 class C {} 58 class C {}
62 f(var p) { 59 f(var p) {
63 C.m = 0; 60 C.m = 0;
64 }'''); 61 }''');
65 computeLibrarySourceErrors(source);
66 assertErrors(source, [StaticWarningCode.UNDEFINED_SETTER]); 62 assertErrors(source, [StaticWarningCode.UNDEFINED_SETTER]);
67 verify([source]); 63 verify([source]);
68 } 64 }
69 65
70 void test_ambiguousImport_as() { 66 void test_ambiguousImport_as() {
71 Source source = addSource(r''' 67 Source source = addSource(r'''
72 import 'lib1.dart'; 68 import 'lib1.dart';
73 import 'lib2.dart'; 69 import 'lib2.dart';
74 f(p) {p as N;}'''); 70 f(p) {p as N;}''');
75 addNamedSource( 71 addNamedSource(
76 "/lib1.dart", 72 "/lib1.dart",
77 r''' 73 r'''
78 library lib1; 74 library lib1;
79 class N {}'''); 75 class N {}''');
80 addNamedSource( 76 addNamedSource(
81 "/lib2.dart", 77 "/lib2.dart",
82 r''' 78 r'''
83 library lib2; 79 library lib2;
84 class N {}'''); 80 class N {}''');
85 computeLibrarySourceErrors(source);
86 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 81 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
87 } 82 }
88 83
89 void test_ambiguousImport_extends() { 84 void test_ambiguousImport_extends() {
90 Source source = addSource(r''' 85 Source source = addSource(r'''
91 import 'lib1.dart'; 86 import 'lib1.dart';
92 import 'lib2.dart'; 87 import 'lib2.dart';
93 class A extends N {}'''); 88 class A extends N {}''');
94 addNamedSource( 89 addNamedSource(
95 "/lib1.dart", 90 "/lib1.dart",
96 r''' 91 r'''
97 library lib1; 92 library lib1;
98 class N {}'''); 93 class N {}''');
99 addNamedSource( 94 addNamedSource(
100 "/lib2.dart", 95 "/lib2.dart",
101 r''' 96 r'''
102 library lib2; 97 library lib2;
103 class N {}'''); 98 class N {}''');
104 computeLibrarySourceErrors(source);
105 assertErrors(source, [ 99 assertErrors(source, [
106 StaticWarningCode.AMBIGUOUS_IMPORT, 100 StaticWarningCode.AMBIGUOUS_IMPORT,
107 CompileTimeErrorCode.EXTENDS_NON_CLASS 101 CompileTimeErrorCode.EXTENDS_NON_CLASS
108 ]); 102 ]);
109 } 103 }
110 104
111 void test_ambiguousImport_implements() { 105 void test_ambiguousImport_implements() {
112 Source source = addSource(r''' 106 Source source = addSource(r'''
113 import 'lib1.dart'; 107 import 'lib1.dart';
114 import 'lib2.dart'; 108 import 'lib2.dart';
115 class A implements N {}'''); 109 class A implements N {}''');
116 addNamedSource( 110 addNamedSource(
117 "/lib1.dart", 111 "/lib1.dart",
118 r''' 112 r'''
119 library lib1; 113 library lib1;
120 class N {}'''); 114 class N {}''');
121 addNamedSource( 115 addNamedSource(
122 "/lib2.dart", 116 "/lib2.dart",
123 r''' 117 r'''
124 library lib2; 118 library lib2;
125 class N {}'''); 119 class N {}''');
126 computeLibrarySourceErrors(source);
127 assertErrors(source, [ 120 assertErrors(source, [
128 StaticWarningCode.AMBIGUOUS_IMPORT, 121 StaticWarningCode.AMBIGUOUS_IMPORT,
129 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS 122 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS
130 ]); 123 ]);
131 } 124 }
132 125
133 void test_ambiguousImport_inPart() { 126 void test_ambiguousImport_inPart() {
134 Source source = addSource(r''' 127 Source source = addSource(r'''
135 library lib; 128 library lib;
136 import 'lib1.dart'; 129 import 'lib1.dart';
137 import 'lib2.dart'; 130 import 'lib2.dart';
138 part 'part.dart';'''); 131 part 'part.dart';''');
139 addNamedSource( 132 addNamedSource(
140 "/lib1.dart", 133 "/lib1.dart",
141 r''' 134 r'''
142 library lib1; 135 library lib1;
143 class N {}'''); 136 class N {}''');
144 addNamedSource( 137 addNamedSource(
145 "/lib2.dart", 138 "/lib2.dart",
146 r''' 139 r'''
147 library lib2; 140 library lib2;
148 class N {}'''); 141 class N {}''');
149 Source partSource = addNamedSource( 142 Source partSource = addNamedSource(
150 "/part.dart", 143 "/part.dart",
151 r''' 144 r'''
152 part of lib; 145 part of lib;
153 class A extends N {}'''); 146 class A extends N {}''');
154 computeLibrarySourceErrors(source); 147 assertNoErrors(source);
155 assertErrors(partSource, [ 148 assertErrors(partSource, [
156 StaticWarningCode.AMBIGUOUS_IMPORT, 149 StaticWarningCode.AMBIGUOUS_IMPORT,
157 CompileTimeErrorCode.EXTENDS_NON_CLASS 150 CompileTimeErrorCode.EXTENDS_NON_CLASS
158 ]); 151 ]);
159 } 152 }
160 153
161 void test_ambiguousImport_instanceCreation() { 154 void test_ambiguousImport_instanceCreation() {
162 Source source = addSource(r''' 155 Source source = addSource(r'''
163 library L; 156 library L;
164 import 'lib1.dart'; 157 import 'lib1.dart';
165 import 'lib2.dart'; 158 import 'lib2.dart';
166 f() {new N();}'''); 159 f() {new N();}''');
167 addNamedSource( 160 addNamedSource(
168 "/lib1.dart", 161 "/lib1.dart",
169 r''' 162 r'''
170 library lib1; 163 library lib1;
171 class N {}'''); 164 class N {}''');
172 addNamedSource( 165 addNamedSource(
173 "/lib2.dart", 166 "/lib2.dart",
174 r''' 167 r'''
175 library lib2; 168 library lib2;
176 class N {}'''); 169 class N {}''');
177 computeLibrarySourceErrors(source);
178 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 170 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
179 } 171 }
180 172
181 void test_ambiguousImport_is() { 173 void test_ambiguousImport_is() {
182 Source source = addSource(r''' 174 Source source = addSource(r'''
183 import 'lib1.dart'; 175 import 'lib1.dart';
184 import 'lib2.dart'; 176 import 'lib2.dart';
185 f(p) {p is N;}'''); 177 f(p) {p is N;}''');
186 addNamedSource( 178 addNamedSource(
187 "/lib1.dart", 179 "/lib1.dart",
188 r''' 180 r'''
189 library lib1; 181 library lib1;
190 class N {}'''); 182 class N {}''');
191 addNamedSource( 183 addNamedSource(
192 "/lib2.dart", 184 "/lib2.dart",
193 r''' 185 r'''
194 library lib2; 186 library lib2;
195 class N {}'''); 187 class N {}''');
196 computeLibrarySourceErrors(source);
197 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 188 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
198 } 189 }
199 190
200 void test_ambiguousImport_qualifier() { 191 void test_ambiguousImport_qualifier() {
201 Source source = addSource(r''' 192 Source source = addSource(r'''
202 import 'lib1.dart'; 193 import 'lib1.dart';
203 import 'lib2.dart'; 194 import 'lib2.dart';
204 g() { N.FOO; }'''); 195 g() { N.FOO; }''');
205 addNamedSource( 196 addNamedSource(
206 "/lib1.dart", 197 "/lib1.dart",
207 r''' 198 r'''
208 library lib1; 199 library lib1;
209 class N {}'''); 200 class N {}''');
210 addNamedSource( 201 addNamedSource(
211 "/lib2.dart", 202 "/lib2.dart",
212 r''' 203 r'''
213 library lib2; 204 library lib2;
214 class N {}'''); 205 class N {}''');
215 computeLibrarySourceErrors(source);
216 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 206 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
217 } 207 }
218 208
219 void test_ambiguousImport_typeAnnotation() { 209 void test_ambiguousImport_typeAnnotation() {
220 Source source = addSource(r''' 210 Source source = addSource(r'''
221 import 'lib1.dart'; 211 import 'lib1.dart';
222 import 'lib2.dart'; 212 import 'lib2.dart';
223 typedef N FT(N p); 213 typedef N FT(N p);
224 N f(N p) { 214 N f(N p) {
225 N v; 215 N v;
226 return null; 216 return null;
227 } 217 }
228 class A { 218 class A {
229 N m() { return null; } 219 N m() { return null; }
230 } 220 }
231 class B<T extends N> {}'''); 221 class B<T extends N> {}''');
232 addNamedSource( 222 addNamedSource(
233 "/lib1.dart", 223 "/lib1.dart",
234 r''' 224 r'''
235 library lib1; 225 library lib1;
236 class N {}'''); 226 class N {}''');
237 addNamedSource( 227 addNamedSource(
238 "/lib2.dart", 228 "/lib2.dart",
239 r''' 229 r'''
240 library lib2; 230 library lib2;
241 class N {}'''); 231 class N {}''');
242 computeLibrarySourceErrors(source);
243 assertErrors(source, [ 232 assertErrors(source, [
244 StaticWarningCode.AMBIGUOUS_IMPORT, 233 StaticWarningCode.AMBIGUOUS_IMPORT,
245 StaticWarningCode.AMBIGUOUS_IMPORT, 234 StaticWarningCode.AMBIGUOUS_IMPORT,
246 StaticWarningCode.AMBIGUOUS_IMPORT, 235 StaticWarningCode.AMBIGUOUS_IMPORT,
247 StaticWarningCode.AMBIGUOUS_IMPORT, 236 StaticWarningCode.AMBIGUOUS_IMPORT,
248 StaticWarningCode.AMBIGUOUS_IMPORT, 237 StaticWarningCode.AMBIGUOUS_IMPORT,
249 StaticWarningCode.AMBIGUOUS_IMPORT, 238 StaticWarningCode.AMBIGUOUS_IMPORT,
250 StaticWarningCode.AMBIGUOUS_IMPORT 239 StaticWarningCode.AMBIGUOUS_IMPORT
251 ]); 240 ]);
252 } 241 }
253 242
254 void test_ambiguousImport_typeArgument_annotation() { 243 void test_ambiguousImport_typeArgument_annotation() {
255 Source source = addSource(r''' 244 Source source = addSource(r'''
256 import 'lib1.dart'; 245 import 'lib1.dart';
257 import 'lib2.dart'; 246 import 'lib2.dart';
258 class A<T> {} 247 class A<T> {}
259 A<N> f() { return null; }'''); 248 A<N> f() { return null; }''');
260 addNamedSource( 249 addNamedSource(
261 "/lib1.dart", 250 "/lib1.dart",
262 r''' 251 r'''
263 library lib1; 252 library lib1;
264 class N {}'''); 253 class N {}''');
265 addNamedSource( 254 addNamedSource(
266 "/lib2.dart", 255 "/lib2.dart",
267 r''' 256 r'''
268 library lib2; 257 library lib2;
269 class N {}'''); 258 class N {}''');
270 computeLibrarySourceErrors(source);
271 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 259 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
272 } 260 }
273 261
274 void test_ambiguousImport_typeArgument_instanceCreation() { 262 void test_ambiguousImport_typeArgument_instanceCreation() {
275 Source source = addSource(r''' 263 Source source = addSource(r'''
276 import 'lib1.dart'; 264 import 'lib1.dart';
277 import 'lib2.dart'; 265 import 'lib2.dart';
278 class A<T> {} 266 class A<T> {}
279 f() {new A<N>();}'''); 267 f() {new A<N>();}''');
280 addNamedSource( 268 addNamedSource(
281 "/lib1.dart", 269 "/lib1.dart",
282 r''' 270 r'''
283 library lib1; 271 library lib1;
284 class N {}'''); 272 class N {}''');
285 addNamedSource( 273 addNamedSource(
286 "/lib2.dart", 274 "/lib2.dart",
287 r''' 275 r'''
288 library lib2; 276 library lib2;
289 class N {}'''); 277 class N {}''');
290 computeLibrarySourceErrors(source);
291 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 278 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
292 } 279 }
293 280
294 void test_ambiguousImport_varRead() { 281 void test_ambiguousImport_varRead() {
295 Source source = addSource(r''' 282 Source source = addSource(r'''
296 import 'lib1.dart'; 283 import 'lib1.dart';
297 import 'lib2.dart'; 284 import 'lib2.dart';
298 f() { g(v); } 285 f() { g(v); }
299 g(p) {}'''); 286 g(p) {}''');
300 addNamedSource( 287 addNamedSource(
301 "/lib1.dart", 288 "/lib1.dart",
302 r''' 289 r'''
303 library lib1; 290 library lib1;
304 var v;'''); 291 var v;''');
305 addNamedSource( 292 addNamedSource(
306 "/lib2.dart", 293 "/lib2.dart",
307 r''' 294 r'''
308 library lib2; 295 library lib2;
309 var v;'''); 296 var v;''');
310 computeLibrarySourceErrors(source);
311 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 297 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
312 } 298 }
313 299
314 void test_ambiguousImport_varWrite() { 300 void test_ambiguousImport_varWrite() {
315 Source source = addSource(r''' 301 Source source = addSource(r'''
316 import 'lib1.dart'; 302 import 'lib1.dart';
317 import 'lib2.dart'; 303 import 'lib2.dart';
318 f() { v = 0; }'''); 304 f() { v = 0; }''');
319 addNamedSource( 305 addNamedSource(
320 "/lib1.dart", 306 "/lib1.dart",
321 r''' 307 r'''
322 library lib1; 308 library lib1;
323 var v;'''); 309 var v;''');
324 addNamedSource( 310 addNamedSource(
325 "/lib2.dart", 311 "/lib2.dart",
326 r''' 312 r'''
327 library lib2; 313 library lib2;
328 var v;'''); 314 var v;''');
329 computeLibrarySourceErrors(source);
330 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 315 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
331 } 316 }
332 317
333 void test_ambiguousImport_withPrefix() { 318 void test_ambiguousImport_withPrefix() {
334 Source source = addSource(r''' 319 Source source = addSource(r'''
335 library test; 320 library test;
336 import 'lib1.dart' as p; 321 import 'lib1.dart' as p;
337 import 'lib2.dart' as p; 322 import 'lib2.dart' as p;
338 main() { 323 main() {
339 p.f(); 324 p.f();
340 }'''); 325 }''');
341 addNamedSource( 326 addNamedSource(
342 "/lib1.dart", 327 "/lib1.dart",
343 r''' 328 r'''
344 library lib1; 329 library lib1;
345 f() {}'''); 330 f() {}''');
346 addNamedSource( 331 addNamedSource(
347 "/lib2.dart", 332 "/lib2.dart",
348 r''' 333 r'''
349 library lib2; 334 library lib2;
350 f() {}'''); 335 f() {}''');
351 computeLibrarySourceErrors(source);
352 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 336 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
353 } 337 }
354 338
355 void test_argumentTypeNotAssignable_ambiguousClassName() { 339 void test_argumentTypeNotAssignable_ambiguousClassName() {
356 // See dartbug.com/19624 340 // See dartbug.com/19624
357 Source source = addNamedSource( 341 Source source = addNamedSource(
358 "/lib1.dart", 342 "/lib1.dart",
359 r''' 343 r'''
360 library lib1; 344 library lib1;
361 import 'lib2.dart'; 345 import 'lib2.dart';
362 class _A {} 346 class _A {}
363 f() { 347 f() {
364 g((_A a) {}); 348 g((_A a) {});
365 }'''); 349 }''');
366 addNamedSource( 350 addNamedSource(
367 "/lib2.dart", 351 "/lib2.dart",
368 r''' 352 r'''
369 library lib2; 353 library lib2;
370 class _A {} 354 class _A {}
371 g(h(_A a)) {}'''); 355 g(h(_A a)) {}''');
372 computeLibrarySourceErrors(source);
373 // The name _A is private to the library it's defined in, so this is a type 356 // The name _A is private to the library it's defined in, so this is a type
374 // mismatch. Furthermore, the error message should mention both _A and the 357 // mismatch. Furthermore, the error message should mention both _A and the
375 // filenames so the user can figure out what's going on. 358 // filenames so the user can figure out what's going on.
376 List<AnalysisError> errors = analysisContext2.computeErrors(source); 359 List<AnalysisError> errors = analysisContext2.computeErrors(source);
377 expect(errors, hasLength(1)); 360 expect(errors, hasLength(1));
378 AnalysisError error = errors[0]; 361 AnalysisError error = errors[0];
379 expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, error.errorCode); 362 expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, error.errorCode);
380 String message = error.message; 363 String message = error.message;
381 expect(message.indexOf("_A") != -1, isTrue); 364 expect(message.indexOf("_A") != -1, isTrue);
382 expect(message.indexOf("lib1.dart") != -1, isTrue); 365 expect(message.indexOf("lib1.dart") != -1, isTrue);
383 expect(message.indexOf("lib2.dart") != -1, isTrue); 366 expect(message.indexOf("lib2.dart") != -1, isTrue);
384 } 367 }
385 368
386 void test_argumentTypeNotAssignable_annotation_namedConstructor() { 369 void test_argumentTypeNotAssignable_annotation_namedConstructor() {
387 Source source = addSource(r''' 370 Source source = addSource(r'''
388 class A { 371 class A {
389 const A.fromInt(int p); 372 const A.fromInt(int p);
390 } 373 }
391 @A.fromInt('0') 374 @A.fromInt('0')
392 main() { 375 main() {
393 }'''); 376 }''');
394 computeLibrarySourceErrors(source);
395 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 377 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
396 verify([source]); 378 verify([source]);
397 } 379 }
398 380
399 void test_argumentTypeNotAssignable_annotation_unnamedConstructor() { 381 void test_argumentTypeNotAssignable_annotation_unnamedConstructor() {
400 Source source = addSource(r''' 382 Source source = addSource(r'''
401 class A { 383 class A {
402 const A(int p); 384 const A(int p);
403 } 385 }
404 @A('0') 386 @A('0')
405 main() { 387 main() {
406 }'''); 388 }''');
407 computeLibrarySourceErrors(source);
408 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 389 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
409 verify([source]); 390 verify([source]);
410 } 391 }
411 392
412 void test_argumentTypeNotAssignable_binary() { 393 void test_argumentTypeNotAssignable_binary() {
413 Source source = addSource(r''' 394 Source source = addSource(r'''
414 class A { 395 class A {
415 operator +(int p) {} 396 operator +(int p) {}
416 } 397 }
417 f(A a) { 398 f(A a) {
418 a + '0'; 399 a + '0';
419 }'''); 400 }''');
420 computeLibrarySourceErrors(source);
421 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 401 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
422 verify([source]); 402 verify([source]);
423 } 403 }
424 404
425 void test_argumentTypeNotAssignable_cascadeSecond() { 405 void test_argumentTypeNotAssignable_cascadeSecond() {
426 Source source = addSource(r''' 406 Source source = addSource(r'''
427 // filler filler filler filler filler filler filler filler filler filler 407 // filler filler filler filler filler filler filler filler filler filler
428 class A { 408 class A {
429 B ma() { return new B(); } 409 B ma() { return new B(); }
430 } 410 }
431 class B { 411 class B {
432 mb(String p) {} 412 mb(String p) {}
433 } 413 }
434 414
435 main() { 415 main() {
436 A a = new A(); 416 A a = new A();
437 a.. ma().mb(0); 417 a.. ma().mb(0);
438 }'''); 418 }''');
439 computeLibrarySourceErrors(source);
440 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 419 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
441 verify([source]); 420 verify([source]);
442 } 421 }
443 422
444 void test_argumentTypeNotAssignable_const() { 423 void test_argumentTypeNotAssignable_const() {
445 Source source = addSource(r''' 424 Source source = addSource(r'''
446 class A { 425 class A {
447 const A(String p); 426 const A(String p);
448 } 427 }
449 main() { 428 main() {
450 const A(42); 429 const A(42);
451 }'''); 430 }''');
452 computeLibrarySourceErrors(source);
453 assertErrors(source, [ 431 assertErrors(source, [
454 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 432 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
455 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH 433 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
456 ]); 434 ]);
457 verify([source]); 435 verify([source]);
458 } 436 }
459 437
460 void test_argumentTypeNotAssignable_const_super() { 438 void test_argumentTypeNotAssignable_const_super() {
461 Source source = addSource(r''' 439 Source source = addSource(r'''
462 class A { 440 class A {
463 const A(String p); 441 const A(String p);
464 } 442 }
465 class B extends A { 443 class B extends A {
466 const B() : super(42); 444 const B() : super(42);
467 }'''); 445 }''');
468 computeLibrarySourceErrors(source);
469 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 446 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
470 verify([source]); 447 verify([source]);
471 } 448 }
472 449
473 void test_argumentTypeNotAssignable_functionExpressionInvocation_required() { 450 void test_argumentTypeNotAssignable_functionExpressionInvocation_required() {
474 Source source = addSource(r''' 451 Source source = addSource(r'''
475 main() { 452 main() {
476 (int x) {} (''); 453 (int x) {} ('');
477 }'''); 454 }''');
478 computeLibrarySourceErrors(source);
479 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 455 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
480 verify([source]); 456 verify([source]);
481 } 457 }
482 458
483 void test_argumentTypeNotAssignable_index() { 459 void test_argumentTypeNotAssignable_index() {
484 Source source = addSource(r''' 460 Source source = addSource(r'''
485 class A { 461 class A {
486 operator [](int index) {} 462 operator [](int index) {}
487 } 463 }
488 f(A a) { 464 f(A a) {
489 a['0']; 465 a['0'];
490 }'''); 466 }''');
491 computeLibrarySourceErrors(source);
492 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 467 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
493 verify([source]); 468 verify([source]);
494 } 469 }
495 470
496 void test_argumentTypeNotAssignable_invocation_callParameter() { 471 void test_argumentTypeNotAssignable_invocation_callParameter() {
497 Source source = addSource(r''' 472 Source source = addSource(r'''
498 class A { 473 class A {
499 call(int p) {} 474 call(int p) {}
500 } 475 }
501 f(A a) { 476 f(A a) {
502 a('0'); 477 a('0');
503 }'''); 478 }''');
504 computeLibrarySourceErrors(source);
505 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 479 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
506 verify([source]); 480 verify([source]);
507 } 481 }
508 482
509 void test_argumentTypeNotAssignable_invocation_callVariable() { 483 void test_argumentTypeNotAssignable_invocation_callVariable() {
510 Source source = addSource(r''' 484 Source source = addSource(r'''
511 class A { 485 class A {
512 call(int p) {} 486 call(int p) {}
513 } 487 }
514 main() { 488 main() {
515 A a = new A(); 489 A a = new A();
516 a('0'); 490 a('0');
517 }'''); 491 }''');
518 computeLibrarySourceErrors(source);
519 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 492 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
520 verify([source]); 493 verify([source]);
521 } 494 }
522 495
523 void test_argumentTypeNotAssignable_invocation_functionParameter() { 496 void test_argumentTypeNotAssignable_invocation_functionParameter() {
524 Source source = addSource(r''' 497 Source source = addSource(r'''
525 a(b(int p)) { 498 a(b(int p)) {
526 b('0'); 499 b('0');
527 }'''); 500 }''');
528 computeLibrarySourceErrors(source);
529 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 501 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
530 verify([source]); 502 verify([source]);
531 } 503 }
532 504
533 void test_argumentTypeNotAssignable_invocation_functionParameter_generic() { 505 void test_argumentTypeNotAssignable_invocation_functionParameter_generic() {
534 Source source = addSource(r''' 506 Source source = addSource(r'''
535 class A<K, V> { 507 class A<K, V> {
536 m(f(K k), V v) { 508 m(f(K k), V v) {
537 f(v); 509 f(v);
538 } 510 }
539 }'''); 511 }''');
540 computeLibrarySourceErrors(source);
541 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 512 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
542 verify([source]); 513 verify([source]);
543 } 514 }
544 515
545 void test_argumentTypeNotAssignable_invocation_functionTypes_optional() { 516 void test_argumentTypeNotAssignable_invocation_functionTypes_optional() {
546 Source source = addSource(r''' 517 Source source = addSource(r'''
547 void acceptFunNumOptBool(void funNumOptBool([bool b])) {} 518 void acceptFunNumOptBool(void funNumOptBool([bool b])) {}
548 void funNumBool(bool b) {} 519 void funNumBool(bool b) {}
549 main() { 520 main() {
550 acceptFunNumOptBool(funNumBool); 521 acceptFunNumOptBool(funNumBool);
551 }'''); 522 }''');
552 computeLibrarySourceErrors(source);
553 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 523 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
554 verify([source]); 524 verify([source]);
555 } 525 }
556 526
557 void test_argumentTypeNotAssignable_invocation_generic() { 527 void test_argumentTypeNotAssignable_invocation_generic() {
558 Source source = addSource(r''' 528 Source source = addSource(r'''
559 class A<T> { 529 class A<T> {
560 m(T t) {} 530 m(T t) {}
561 } 531 }
562 f(A<String> a) { 532 f(A<String> a) {
563 a.m(1); 533 a.m(1);
564 }'''); 534 }''');
565 computeLibrarySourceErrors(source);
566 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 535 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
567 verify([source]); 536 verify([source]);
568 } 537 }
569 538
570 void test_argumentTypeNotAssignable_invocation_named() { 539 void test_argumentTypeNotAssignable_invocation_named() {
571 Source source = addSource(r''' 540 Source source = addSource(r'''
572 f({String p}) {} 541 f({String p}) {}
573 main() { 542 main() {
574 f(p: 42); 543 f(p: 42);
575 }'''); 544 }''');
576 computeLibrarySourceErrors(source);
577 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 545 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
578 verify([source]); 546 verify([source]);
579 } 547 }
580 548
581 void test_argumentTypeNotAssignable_invocation_optional() { 549 void test_argumentTypeNotAssignable_invocation_optional() {
582 Source source = addSource(r''' 550 Source source = addSource(r'''
583 f([String p]) {} 551 f([String p]) {}
584 main() { 552 main() {
585 f(42); 553 f(42);
586 }'''); 554 }''');
587 computeLibrarySourceErrors(source);
588 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 555 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
589 verify([source]); 556 verify([source]);
590 } 557 }
591 558
592 void test_argumentTypeNotAssignable_invocation_required() { 559 void test_argumentTypeNotAssignable_invocation_required() {
593 Source source = addSource(r''' 560 Source source = addSource(r'''
594 f(String p) {} 561 f(String p) {}
595 main() { 562 main() {
596 f(42); 563 f(42);
597 }'''); 564 }''');
598 computeLibrarySourceErrors(source);
599 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 565 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
600 verify([source]); 566 verify([source]);
601 } 567 }
602 568
603 void test_argumentTypeNotAssignable_invocation_typedef_generic() { 569 void test_argumentTypeNotAssignable_invocation_typedef_generic() {
604 Source source = addSource(r''' 570 Source source = addSource(r'''
605 typedef A<T>(T p); 571 typedef A<T>(T p);
606 f(A<int> a) { 572 f(A<int> a) {
607 a('1'); 573 a('1');
608 }'''); 574 }''');
609 computeLibrarySourceErrors(source);
610 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 575 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
611 verify([source]); 576 verify([source]);
612 } 577 }
613 578
614 void test_argumentTypeNotAssignable_invocation_typedef_local() { 579 void test_argumentTypeNotAssignable_invocation_typedef_local() {
615 Source source = addSource(r''' 580 Source source = addSource(r'''
616 typedef A(int p); 581 typedef A(int p);
617 A getA() => null; 582 A getA() => null;
618 main() { 583 main() {
619 A a = getA(); 584 A a = getA();
620 a('1'); 585 a('1');
621 }'''); 586 }''');
622 computeLibrarySourceErrors(source);
623 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 587 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
624 verify([source]); 588 verify([source]);
625 } 589 }
626 590
627 void test_argumentTypeNotAssignable_invocation_typedef_parameter() { 591 void test_argumentTypeNotAssignable_invocation_typedef_parameter() {
628 Source source = addSource(r''' 592 Source source = addSource(r'''
629 typedef A(int p); 593 typedef A(int p);
630 f(A a) { 594 f(A a) {
631 a('1'); 595 a('1');
632 }'''); 596 }''');
633 computeLibrarySourceErrors(source);
634 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 597 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
635 verify([source]); 598 verify([source]);
636 } 599 }
637 600
638 void test_argumentTypeNotAssignable_new_generic() { 601 void test_argumentTypeNotAssignable_new_generic() {
639 Source source = addSource(r''' 602 Source source = addSource(r'''
640 class A<T> { 603 class A<T> {
641 A(T p) {} 604 A(T p) {}
642 } 605 }
643 main() { 606 main() {
644 new A<String>(42); 607 new A<String>(42);
645 }'''); 608 }''');
646 computeLibrarySourceErrors(source);
647 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 609 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
648 verify([source]); 610 verify([source]);
649 } 611 }
650 612
651 void test_argumentTypeNotAssignable_new_optional() { 613 void test_argumentTypeNotAssignable_new_optional() {
652 Source source = addSource(r''' 614 Source source = addSource(r'''
653 class A { 615 class A {
654 A([String p]) {} 616 A([String p]) {}
655 } 617 }
656 main() { 618 main() {
657 new A(42); 619 new A(42);
658 }'''); 620 }''');
659 computeLibrarySourceErrors(source);
660 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 621 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
661 verify([source]); 622 verify([source]);
662 } 623 }
663 624
664 void test_argumentTypeNotAssignable_new_required() { 625 void test_argumentTypeNotAssignable_new_required() {
665 Source source = addSource(r''' 626 Source source = addSource(r'''
666 class A { 627 class A {
667 A(String p) {} 628 A(String p) {}
668 } 629 }
669 main() { 630 main() {
670 new A(42); 631 new A(42);
671 }'''); 632 }''');
672 computeLibrarySourceErrors(source);
673 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 633 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
674 verify([source]); 634 verify([source]);
675 } 635 }
676 636
677 void test_assignmentToClass() { 637 void test_assignmentToClass() {
678 Source source = addSource(''' 638 Source source = addSource('''
679 class C {} 639 class C {}
680 main() { 640 main() {
681 C = null; 641 C = null;
682 } 642 }
683 '''); 643 ''');
684 computeLibrarySourceErrors(source);
685 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); 644 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]);
686 } 645 }
687 646
688 void test_assignmentToConst_instanceVariable() { 647 void test_assignmentToConst_instanceVariable() {
689 Source source = addSource(r''' 648 Source source = addSource(r'''
690 class A { 649 class A {
691 static const v = 0; 650 static const v = 0;
692 } 651 }
693 f() { 652 f() {
694 A.v = 1; 653 A.v = 1;
695 }'''); 654 }''');
696 computeLibrarySourceErrors(source);
697 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); 655 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]);
698 verify([source]); 656 verify([source]);
699 } 657 }
700 658
701 void test_assignmentToConst_instanceVariable_plusEq() { 659 void test_assignmentToConst_instanceVariable_plusEq() {
702 Source source = addSource(r''' 660 Source source = addSource(r'''
703 class A { 661 class A {
704 static const v = 0; 662 static const v = 0;
705 } 663 }
706 f() { 664 f() {
707 A.v += 1; 665 A.v += 1;
708 }'''); 666 }''');
709 computeLibrarySourceErrors(source);
710 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); 667 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]);
711 verify([source]); 668 verify([source]);
712 } 669 }
713 670
714 void test_assignmentToConst_localVariable() { 671 void test_assignmentToConst_localVariable() {
715 Source source = addSource(r''' 672 Source source = addSource(r'''
716 f() { 673 f() {
717 const x = 0; 674 const x = 0;
718 x = 1; 675 x = 1;
719 }'''); 676 }''');
720 computeLibrarySourceErrors(source);
721 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); 677 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]);
722 verify([source]); 678 verify([source]);
723 } 679 }
724 680
725 void test_assignmentToConst_localVariable_plusEq() { 681 void test_assignmentToConst_localVariable_plusEq() {
726 Source source = addSource(r''' 682 Source source = addSource(r'''
727 f() { 683 f() {
728 const x = 0; 684 const x = 0;
729 x += 1; 685 x += 1;
730 }'''); 686 }''');
731 computeLibrarySourceErrors(source);
732 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); 687 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]);
733 verify([source]); 688 verify([source]);
734 } 689 }
735 690
736 void test_assignmentToEnumType() { 691 void test_assignmentToEnumType() {
737 Source source = addSource(''' 692 Source source = addSource('''
738 enum E { e } 693 enum E { e }
739 main() { 694 main() {
740 E = null; 695 E = null;
741 } 696 }
742 '''); 697 ''');
743 computeLibrarySourceErrors(source);
744 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); 698 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]);
745 } 699 }
746 700
747 void test_assignmentToFinal_instanceVariable() { 701 void test_assignmentToFinal_instanceVariable() {
748 Source source = addSource(r''' 702 Source source = addSource(r'''
749 class A { 703 class A {
750 final v = 0; 704 final v = 0;
751 } 705 }
752 f() { 706 f() {
753 A a = new A(); 707 A a = new A();
754 a.v = 1; 708 a.v = 1;
755 }'''); 709 }''');
756 computeLibrarySourceErrors(source);
757 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 710 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
758 verify([source]); 711 verify([source]);
759 } 712 }
760 713
761 void test_assignmentToFinal_instanceVariable_plusEq() { 714 void test_assignmentToFinal_instanceVariable_plusEq() {
762 Source source = addSource(r''' 715 Source source = addSource(r'''
763 class A { 716 class A {
764 final v = 0; 717 final v = 0;
765 } 718 }
766 f() { 719 f() {
767 A a = new A(); 720 A a = new A();
768 a.v += 1; 721 a.v += 1;
769 }'''); 722 }''');
770 computeLibrarySourceErrors(source);
771 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 723 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
772 verify([source]); 724 verify([source]);
773 } 725 }
774 726
775 void test_assignmentToFinal_localVariable() { 727 void test_assignmentToFinal_localVariable() {
776 Source source = addSource(r''' 728 Source source = addSource(r'''
777 f() { 729 f() {
778 final x = 0; 730 final x = 0;
779 x = 1; 731 x = 1;
780 }'''); 732 }''');
781 computeLibrarySourceErrors(source);
782 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 733 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
783 verify([source]); 734 verify([source]);
784 } 735 }
785 736
786 void test_assignmentToFinal_localVariable_plusEq() { 737 void test_assignmentToFinal_localVariable_plusEq() {
787 Source source = addSource(r''' 738 Source source = addSource(r'''
788 f() { 739 f() {
789 final x = 0; 740 final x = 0;
790 x += 1; 741 x += 1;
791 }'''); 742 }''');
792 computeLibrarySourceErrors(source);
793 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 743 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
794 verify([source]); 744 verify([source]);
795 } 745 }
796 746
797 void test_assignmentToFinal_postfixMinusMinus() { 747 void test_assignmentToFinal_postfixMinusMinus() {
798 Source source = addSource(r''' 748 Source source = addSource(r'''
799 f() { 749 f() {
800 final x = 0; 750 final x = 0;
801 x--; 751 x--;
802 }'''); 752 }''');
803 computeLibrarySourceErrors(source);
804 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 753 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
805 verify([source]); 754 verify([source]);
806 } 755 }
807 756
808 void test_assignmentToFinal_postfixPlusPlus() { 757 void test_assignmentToFinal_postfixPlusPlus() {
809 Source source = addSource(r''' 758 Source source = addSource(r'''
810 f() { 759 f() {
811 final x = 0; 760 final x = 0;
812 x++; 761 x++;
813 }'''); 762 }''');
814 computeLibrarySourceErrors(source);
815 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 763 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
816 verify([source]); 764 verify([source]);
817 } 765 }
818 766
819 void test_assignmentToFinal_prefixMinusMinus() { 767 void test_assignmentToFinal_prefixMinusMinus() {
820 Source source = addSource(r''' 768 Source source = addSource(r'''
821 f() { 769 f() {
822 final x = 0; 770 final x = 0;
823 --x; 771 --x;
824 }'''); 772 }''');
825 computeLibrarySourceErrors(source);
826 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 773 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
827 verify([source]); 774 verify([source]);
828 } 775 }
829 776
830 void test_assignmentToFinal_prefixPlusPlus() { 777 void test_assignmentToFinal_prefixPlusPlus() {
831 Source source = addSource(r''' 778 Source source = addSource(r'''
832 f() { 779 f() {
833 final x = 0; 780 final x = 0;
834 ++x; 781 ++x;
835 }'''); 782 }''');
836 computeLibrarySourceErrors(source);
837 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 783 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
838 verify([source]); 784 verify([source]);
839 } 785 }
840 786
841 void test_assignmentToFinal_suffixMinusMinus() { 787 void test_assignmentToFinal_suffixMinusMinus() {
842 Source source = addSource(r''' 788 Source source = addSource(r'''
843 f() { 789 f() {
844 final x = 0; 790 final x = 0;
845 x--; 791 x--;
846 }'''); 792 }''');
847 computeLibrarySourceErrors(source);
848 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 793 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
849 verify([source]); 794 verify([source]);
850 } 795 }
851 796
852 void test_assignmentToFinal_suffixPlusPlus() { 797 void test_assignmentToFinal_suffixPlusPlus() {
853 Source source = addSource(r''' 798 Source source = addSource(r'''
854 f() { 799 f() {
855 final x = 0; 800 final x = 0;
856 x++; 801 x++;
857 }'''); 802 }''');
858 computeLibrarySourceErrors(source);
859 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 803 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
860 verify([source]); 804 verify([source]);
861 } 805 }
862 806
863 void test_assignmentToFinal_topLevelVariable() { 807 void test_assignmentToFinal_topLevelVariable() {
864 Source source = addSource(r''' 808 Source source = addSource(r'''
865 final x = 0; 809 final x = 0;
866 f() { x = 1; }'''); 810 f() { x = 1; }''');
867 computeLibrarySourceErrors(source);
868 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]); 811 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL]);
869 verify([source]); 812 verify([source]);
870 } 813 }
871 814
872 void test_assignmentToFinalNoSetter_prefixedIdentifier() { 815 void test_assignmentToFinalNoSetter_prefixedIdentifier() {
873 Source source = addSource(r''' 816 Source source = addSource(r'''
874 class A { 817 class A {
875 int get x => 0; 818 int get x => 0;
876 } 819 }
877 main() { 820 main() {
878 A a = new A(); 821 A a = new A();
879 a.x = 0; 822 a.x = 0;
880 }'''); 823 }''');
881 computeLibrarySourceErrors(source);
882 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER]); 824 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER]);
883 verify([source]); 825 verify([source]);
884 } 826 }
885 827
886 void test_assignmentToFinalNoSetter_propertyAccess() { 828 void test_assignmentToFinalNoSetter_propertyAccess() {
887 Source source = addSource(r''' 829 Source source = addSource(r'''
888 class A { 830 class A {
889 int get x => 0; 831 int get x => 0;
890 } 832 }
891 class B { 833 class B {
892 static A a; 834 static A a;
893 } 835 }
894 main() { 836 main() {
895 B.a.x = 0; 837 B.a.x = 0;
896 }'''); 838 }''');
897 computeLibrarySourceErrors(source);
898 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER]); 839 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER]);
899 verify([source]); 840 verify([source]);
900 } 841 }
901 842
902 void test_assignmentToFunction() { 843 void test_assignmentToFunction() {
903 Source source = addSource(r''' 844 Source source = addSource(r'''
904 f() {} 845 f() {}
905 main() { 846 main() {
906 f = null; 847 f = null;
907 }'''); 848 }''');
908 computeLibrarySourceErrors(source);
909 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FUNCTION]); 849 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_FUNCTION]);
910 verify([source]); 850 verify([source]);
911 } 851 }
912 852
913 void test_assignmentToMethod() { 853 void test_assignmentToMethod() {
914 Source source = addSource(r''' 854 Source source = addSource(r'''
915 class A { 855 class A {
916 m() {} 856 m() {}
917 } 857 }
918 f(A a) { 858 f(A a) {
919 a.m = () {}; 859 a.m = () {};
920 }'''); 860 }''');
921 computeLibrarySourceErrors(source);
922 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_METHOD]); 861 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_METHOD]);
923 verify([source]); 862 verify([source]);
924 } 863 }
925 864
926 void test_assignmentToTypedef() { 865 void test_assignmentToTypedef() {
927 Source source = addSource(''' 866 Source source = addSource('''
928 typedef void F(); 867 typedef void F();
929 main() { 868 main() {
930 F = null; 869 F = null;
931 } 870 }
932 '''); 871 ''');
933 computeLibrarySourceErrors(source);
934 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); 872 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]);
935 } 873 }
936 874
937 void test_assignmentToTypeParameter() { 875 void test_assignmentToTypeParameter() {
938 Source source = addSource(''' 876 Source source = addSource('''
939 class C<T> { 877 class C<T> {
940 f() { 878 f() {
941 T = null; 879 T = null;
942 } 880 }
943 } 881 }
944 '''); 882 ''');
945 computeLibrarySourceErrors(source);
946 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]); 883 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]);
947 } 884 }
948 885
949 void test_caseBlockNotTerminated() { 886 void test_caseBlockNotTerminated() {
950 Source source = addSource(r''' 887 Source source = addSource(r'''
951 f(int p) { 888 f(int p) {
952 switch (p) { 889 switch (p) {
953 case 0: 890 case 0:
954 f(p); 891 f(p);
955 case 1: 892 case 1:
956 break; 893 break;
957 } 894 }
958 }'''); 895 }''');
959 computeLibrarySourceErrors(source);
960 assertErrors(source, [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]); 896 assertErrors(source, [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]);
961 verify([source]); 897 verify([source]);
962 } 898 }
963 899
964 void test_castToNonType() { 900 void test_castToNonType() {
965 Source source = addSource(r''' 901 Source source = addSource(r'''
966 var A = 0; 902 var A = 0;
967 f(String s) { var x = s as A; }'''); 903 f(String s) { var x = s as A; }''');
968 computeLibrarySourceErrors(source);
969 assertErrors(source, [StaticWarningCode.CAST_TO_NON_TYPE]); 904 assertErrors(source, [StaticWarningCode.CAST_TO_NON_TYPE]);
970 verify([source]); 905 verify([source]);
971 } 906 }
972 907
973 void test_concreteClassWithAbstractMember() { 908 void test_concreteClassWithAbstractMember() {
974 Source source = addSource(r''' 909 Source source = addSource(r'''
975 class A { 910 class A {
976 m(); 911 m();
977 }'''); 912 }''');
978 computeLibrarySourceErrors(source);
979 assertErrors( 913 assertErrors(
980 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]); 914 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]);
981 verify([source]); 915 verify([source]);
982 } 916 }
983 917
984 void test_concreteClassWithAbstractMember_noSuchMethod_interface() { 918 void test_concreteClassWithAbstractMember_noSuchMethod_interface() {
985 Source source = addSource(r''' 919 Source source = addSource(r'''
986 class I { 920 class I {
987 noSuchMethod(v) => ''; 921 noSuchMethod(v) => '';
988 } 922 }
989 class A implements I { 923 class A implements I {
990 m(); 924 m();
991 }'''); 925 }''');
992 computeLibrarySourceErrors(source);
993 assertErrors( 926 assertErrors(
994 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]); 927 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]);
995 verify([source]); 928 verify([source]);
996 } 929 }
997 930
998 void test_conflictingDartImport() { 931 void test_conflictingDartImport() {
999 Source source = addSource(r''' 932 Source source = addSource(r'''
1000 import 'lib.dart'; 933 import 'lib.dart';
1001 import 'dart:async'; 934 import 'dart:async';
1002 Future f = null; 935 Future f = null;
1003 Stream s;'''); 936 Stream s;''');
1004 addNamedSource( 937 addNamedSource(
1005 "/lib.dart", 938 "/lib.dart",
1006 r''' 939 r'''
1007 library lib; 940 library lib;
1008 class Future {}'''); 941 class Future {}''');
1009 computeLibrarySourceErrors(source);
1010 assertErrors(source, [StaticWarningCode.CONFLICTING_DART_IMPORT]); 942 assertErrors(source, [StaticWarningCode.CONFLICTING_DART_IMPORT]);
1011 } 943 }
1012 944
1013 void 945 void
1014 test_conflictingInstanceGetterAndSuperclassMember_declField_direct_setter( ) { 946 test_conflictingInstanceGetterAndSuperclassMember_declField_direct_setter( ) {
1015 Source source = addSource(r''' 947 Source source = addSource(r'''
1016 class A { 948 class A {
1017 static set v(x) {} 949 static set v(x) {}
1018 } 950 }
1019 class B extends A { 951 class B extends A {
1020 var v; 952 var v;
1021 }'''); 953 }''');
1022 computeLibrarySourceErrors(source);
1023 assertErrors(source, 954 assertErrors(source,
1024 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); 955 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]);
1025 verify([source]); 956 verify([source]);
1026 } 957 }
1027 958
1028 void 959 void
1029 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_getter () { 960 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_getter () {
1030 Source source = addSource(r''' 961 Source source = addSource(r'''
1031 class A { 962 class A {
1032 static get v => 0; 963 static get v => 0;
1033 } 964 }
1034 class B extends A { 965 class B extends A {
1035 get v => 0; 966 get v => 0;
1036 }'''); 967 }''');
1037 computeLibrarySourceErrors(source);
1038 assertErrors(source, 968 assertErrors(source,
1039 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); 969 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]);
1040 verify([source]); 970 verify([source]);
1041 } 971 }
1042 972
1043 void 973 void
1044 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_method () { 974 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_method () {
1045 Source source = addSource(r''' 975 Source source = addSource(r'''
1046 class A { 976 class A {
1047 static v() {} 977 static v() {}
1048 } 978 }
1049 class B extends A { 979 class B extends A {
1050 get v => 0; 980 get v => 0;
1051 }'''); 981 }''');
1052 computeLibrarySourceErrors(source);
1053 assertErrors(source, 982 assertErrors(source,
1054 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); 983 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]);
1055 verify([source]); 984 verify([source]);
1056 } 985 }
1057 986
1058 void 987 void
1059 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_setter () { 988 test_conflictingInstanceGetterAndSuperclassMember_declGetter_direct_setter () {
1060 Source source = addSource(r''' 989 Source source = addSource(r'''
1061 class A { 990 class A {
1062 static set v(x) {} 991 static set v(x) {}
1063 } 992 }
1064 class B extends A { 993 class B extends A {
1065 get v => 0; 994 get v => 0;
1066 }'''); 995 }''');
1067 computeLibrarySourceErrors(source);
1068 assertErrors(source, 996 assertErrors(source,
1069 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); 997 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]);
1070 verify([source]); 998 verify([source]);
1071 } 999 }
1072 1000
1073 void test_conflictingInstanceGetterAndSuperclassMember_declGetter_indirect() { 1001 void test_conflictingInstanceGetterAndSuperclassMember_declGetter_indirect() {
1074 Source source = addSource(r''' 1002 Source source = addSource(r'''
1075 class A { 1003 class A {
1076 static int v; 1004 static int v;
1077 } 1005 }
1078 class B extends A {} 1006 class B extends A {}
1079 class C extends B { 1007 class C extends B {
1080 get v => 0; 1008 get v => 0;
1081 }'''); 1009 }''');
1082 computeLibrarySourceErrors(source);
1083 assertErrors(source, 1010 assertErrors(source,
1084 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); 1011 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]);
1085 verify([source]); 1012 verify([source]);
1086 } 1013 }
1087 1014
1088 void test_conflictingInstanceGetterAndSuperclassMember_declGetter_mixin() { 1015 void test_conflictingInstanceGetterAndSuperclassMember_declGetter_mixin() {
1089 Source source = addSource(r''' 1016 Source source = addSource(r'''
1090 class M { 1017 class M {
1091 static int v; 1018 static int v;
1092 } 1019 }
1093 class B extends Object with M { 1020 class B extends Object with M {
1094 get v => 0; 1021 get v => 0;
1095 }'''); 1022 }''');
1096 computeLibrarySourceErrors(source);
1097 assertErrors(source, 1023 assertErrors(source,
1098 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); 1024 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]);
1099 verify([source]); 1025 verify([source]);
1100 } 1026 }
1101 1027
1102 void test_conflictingInstanceGetterAndSuperclassMember_direct_field() { 1028 void test_conflictingInstanceGetterAndSuperclassMember_direct_field() {
1103 Source source = addSource(r''' 1029 Source source = addSource(r'''
1104 class A { 1030 class A {
1105 static int v; 1031 static int v;
1106 } 1032 }
1107 class B extends A { 1033 class B extends A {
1108 get v => 0; 1034 get v => 0;
1109 }'''); 1035 }''');
1110 computeLibrarySourceErrors(source);
1111 assertErrors(source, 1036 assertErrors(source,
1112 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]); 1037 [StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER]);
1113 verify([source]); 1038 verify([source]);
1114 } 1039 }
1115 1040
1116 void test_conflictingInstanceMethodSetter2() { 1041 void test_conflictingInstanceMethodSetter2() {
1117 Source source = addSource(r''' 1042 Source source = addSource(r'''
1118 class A { 1043 class A {
1119 foo() {} 1044 foo() {}
1120 set foo(a) {} 1045 set foo(a) {}
1121 }'''); 1046 }''');
1122 computeLibrarySourceErrors(source);
1123 assertErrors( 1047 assertErrors(
1124 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2]); 1048 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2]);
1125 verify([source]); 1049 verify([source]);
1126 } 1050 }
1127 1051
1128 void test_conflictingInstanceMethodSetter_sameClass() { 1052 void test_conflictingInstanceMethodSetter_sameClass() {
1129 Source source = addSource(r''' 1053 Source source = addSource(r'''
1130 class A { 1054 class A {
1131 set foo(a) {} 1055 set foo(a) {}
1132 foo() {} 1056 foo() {}
1133 }'''); 1057 }''');
1134 computeLibrarySourceErrors(source);
1135 assertErrors( 1058 assertErrors(
1136 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]); 1059 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]);
1137 verify([source]); 1060 verify([source]);
1138 } 1061 }
1139 1062
1140 void test_conflictingInstanceMethodSetter_setterInInterface() { 1063 void test_conflictingInstanceMethodSetter_setterInInterface() {
1141 Source source = addSource(r''' 1064 Source source = addSource(r'''
1142 abstract class A { 1065 abstract class A {
1143 set foo(a); 1066 set foo(a);
1144 } 1067 }
1145 abstract class B implements A { 1068 abstract class B implements A {
1146 foo() {} 1069 foo() {}
1147 }'''); 1070 }''');
1148 computeLibrarySourceErrors(source);
1149 assertErrors( 1071 assertErrors(
1150 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]); 1072 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]);
1151 verify([source]); 1073 verify([source]);
1152 } 1074 }
1153 1075
1154 void test_conflictingInstanceMethodSetter_setterInSuper() { 1076 void test_conflictingInstanceMethodSetter_setterInSuper() {
1155 Source source = addSource(r''' 1077 Source source = addSource(r'''
1156 class A { 1078 class A {
1157 set foo(a) {} 1079 set foo(a) {}
1158 } 1080 }
1159 class B extends A { 1081 class B extends A {
1160 foo() {} 1082 foo() {}
1161 }'''); 1083 }''');
1162 computeLibrarySourceErrors(source);
1163 assertErrors( 1084 assertErrors(
1164 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]); 1085 source, [StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER]);
1165 verify([source]); 1086 verify([source]);
1166 } 1087 }
1167 1088
1168 void test_conflictingInstanceSetterAndSuperclassMember() { 1089 void test_conflictingInstanceSetterAndSuperclassMember() {
1169 Source source = addSource(r''' 1090 Source source = addSource(r'''
1170 class A { 1091 class A {
1171 static int v; 1092 static int v;
1172 } 1093 }
1173 class B extends A { 1094 class B extends A {
1174 set v(x) {} 1095 set v(x) {}
1175 }'''); 1096 }''');
1176 computeLibrarySourceErrors(source);
1177 assertErrors(source, 1097 assertErrors(source,
1178 [StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER]); 1098 [StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER]);
1179 verify([source]); 1099 verify([source]);
1180 } 1100 }
1181 1101
1182 void test_conflictingStaticGetterAndInstanceSetter_mixin() { 1102 void test_conflictingStaticGetterAndInstanceSetter_mixin() {
1183 Source source = addSource(r''' 1103 Source source = addSource(r'''
1184 class A { 1104 class A {
1185 set x(int p) {} 1105 set x(int p) {}
1186 } 1106 }
1187 class B extends Object with A { 1107 class B extends Object with A {
1188 static get x => 0; 1108 static get x => 0;
1189 }'''); 1109 }''');
1190 computeLibrarySourceErrors(source);
1191 assertErrors(source, 1110 assertErrors(source,
1192 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]); 1111 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]);
1193 verify([source]); 1112 verify([source]);
1194 } 1113 }
1195 1114
1196 void test_conflictingStaticGetterAndInstanceSetter_superClass() { 1115 void test_conflictingStaticGetterAndInstanceSetter_superClass() {
1197 Source source = addSource(r''' 1116 Source source = addSource(r'''
1198 class A { 1117 class A {
1199 set x(int p) {} 1118 set x(int p) {}
1200 } 1119 }
1201 class B extends A { 1120 class B extends A {
1202 static get x => 0; 1121 static get x => 0;
1203 }'''); 1122 }''');
1204 computeLibrarySourceErrors(source);
1205 assertErrors(source, 1123 assertErrors(source,
1206 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]); 1124 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]);
1207 verify([source]); 1125 verify([source]);
1208 } 1126 }
1209 1127
1210 void test_conflictingStaticGetterAndInstanceSetter_thisClass() { 1128 void test_conflictingStaticGetterAndInstanceSetter_thisClass() {
1211 Source source = addSource(r''' 1129 Source source = addSource(r'''
1212 class A { 1130 class A {
1213 static get x => 0; 1131 static get x => 0;
1214 set x(int p) {} 1132 set x(int p) {}
1215 }'''); 1133 }''');
1216 computeLibrarySourceErrors(source);
1217 assertErrors(source, 1134 assertErrors(source,
1218 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]); 1135 [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]);
1219 verify([source]); 1136 verify([source]);
1220 } 1137 }
1221 1138
1222 void test_conflictingStaticSetterAndInstanceMember_thisClass_getter() { 1139 void test_conflictingStaticSetterAndInstanceMember_thisClass_getter() {
1223 Source source = addSource(r''' 1140 Source source = addSource(r'''
1224 class A { 1141 class A {
1225 get x => 0; 1142 get x => 0;
1226 static set x(int p) {} 1143 static set x(int p) {}
1227 }'''); 1144 }''');
1228 computeLibrarySourceErrors(source);
1229 assertErrors(source, 1145 assertErrors(source,
1230 [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]); 1146 [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]);
1231 verify([source]); 1147 verify([source]);
1232 } 1148 }
1233 1149
1234 void test_conflictingStaticSetterAndInstanceMember_thisClass_method() { 1150 void test_conflictingStaticSetterAndInstanceMember_thisClass_method() {
1235 Source source = addSource(r''' 1151 Source source = addSource(r'''
1236 class A { 1152 class A {
1237 x() {} 1153 x() {}
1238 static set x(int p) {} 1154 static set x(int p) {}
1239 }'''); 1155 }''');
1240 computeLibrarySourceErrors(source);
1241 assertErrors(source, 1156 assertErrors(source,
1242 [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]); 1157 [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]);
1243 verify([source]); 1158 verify([source]);
1244 } 1159 }
1245 1160
1246 void test_constWithAbstractClass() { 1161 void test_constWithAbstractClass() {
1247 Source source = addSource(r''' 1162 Source source = addSource(r'''
1248 abstract class A { 1163 abstract class A {
1249 const A(); 1164 const A();
1250 } 1165 }
1251 void f() { 1166 void f() {
1252 A a = const A(); 1167 A a = const A();
1253 }'''); 1168 }''');
1254 computeLibrarySourceErrors(source);
1255 assertErrors(source, [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS]); 1169 assertErrors(source, [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS]);
1256 verify([source]); 1170 verify([source]);
1257 } 1171 }
1258 1172
1259 void test_equalKeysInMap() { 1173 void test_equalKeysInMap() {
1260 Source source = addSource("var m = {'a' : 0, 'b' : 1, 'a' : 2};"); 1174 Source source = addSource("var m = {'a' : 0, 'b' : 1, 'a' : 2};");
1261 computeLibrarySourceErrors(source);
1262 assertErrors(source, [StaticWarningCode.EQUAL_KEYS_IN_MAP]); 1175 assertErrors(source, [StaticWarningCode.EQUAL_KEYS_IN_MAP]);
1263 verify([source]); 1176 verify([source]);
1264 } 1177 }
1265 1178
1266 void test_equalKeysInMap_withEqualTypeParams() { 1179 void test_equalKeysInMap_withEqualTypeParams() {
1267 Source source = addSource(r''' 1180 Source source = addSource(r'''
1268 class A<T> { 1181 class A<T> {
1269 const A(); 1182 const A();
1270 } 1183 }
1271 var m = {const A<int>(): 0, const A<int>(): 1};'''); 1184 var m = {const A<int>(): 0, const A<int>(): 1};''');
1272 computeLibrarySourceErrors(source);
1273 assertErrors(source, [StaticWarningCode.EQUAL_KEYS_IN_MAP]); 1185 assertErrors(source, [StaticWarningCode.EQUAL_KEYS_IN_MAP]);
1274 verify([source]); 1186 verify([source]);
1275 } 1187 }
1276 1188
1277 void test_equalKeysInMap_withUnequalTypeParams() { 1189 void test_equalKeysInMap_withUnequalTypeParams() {
1278 // No error should be produced because A<int> and A<num> are different 1190 // No error should be produced because A<int> and A<num> are different
1279 // types. 1191 // types.
1280 Source source = addSource(r''' 1192 Source source = addSource(r'''
1281 class A<T> { 1193 class A<T> {
1282 const A(); 1194 const A();
1283 } 1195 }
1284 var m = {const A<int>(): 0, const A<num>(): 1};'''); 1196 var m = {const A<int>(): 0, const A<num>(): 1};''');
1285 computeLibrarySourceErrors(source);
1286 assertNoErrors(source); 1197 assertNoErrors(source);
1287 verify([source]); 1198 verify([source]);
1288 } 1199 }
1289 1200
1290 void test_exportDuplicatedLibraryNamed() { 1201 void test_exportDuplicatedLibraryNamed() {
1291 Source source = addSource(r''' 1202 Source source = addSource(r'''
1292 library test; 1203 library test;
1293 export 'lib1.dart'; 1204 export 'lib1.dart';
1294 export 'lib2.dart';'''); 1205 export 'lib2.dart';''');
1295 addNamedSource("/lib1.dart", "library lib;"); 1206 addNamedSource("/lib1.dart", "library lib;");
1296 addNamedSource("/lib2.dart", "library lib;"); 1207 addNamedSource("/lib2.dart", "library lib;");
1297 computeLibrarySourceErrors(source);
1298 assertErrors(source, [StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_NAMED]); 1208 assertErrors(source, [StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_NAMED]);
1299 verify([source]); 1209 verify([source]);
1300 } 1210 }
1301 1211
1302 void test_extraPositionalArguments() { 1212 void test_extraPositionalArguments() {
1303 Source source = addSource(r''' 1213 Source source = addSource(r'''
1304 f() {} 1214 f() {}
1305 main() { 1215 main() {
1306 f(0, 1, '2'); 1216 f(0, 1, '2');
1307 }'''); 1217 }''');
1308 computeLibrarySourceErrors(source);
1309 assertErrors(source, [StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS]); 1218 assertErrors(source, [StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS]);
1310 verify([source]); 1219 verify([source]);
1311 } 1220 }
1312 1221
1313 void test_extraPositionalArguments_functionExpression() { 1222 void test_extraPositionalArguments_functionExpression() {
1314 Source source = addSource(r''' 1223 Source source = addSource(r'''
1315 main() { 1224 main() {
1316 (int x) {} (0, 1); 1225 (int x) {} (0, 1);
1317 }'''); 1226 }''');
1318 computeLibrarySourceErrors(source);
1319 assertErrors(source, [StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS]); 1227 assertErrors(source, [StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS]);
1320 verify([source]); 1228 verify([source]);
1321 } 1229 }
1322 1230
1323 void test_fieldInitializedInInitializerAndDeclaration_final() { 1231 void test_fieldInitializedInInitializerAndDeclaration_final() {
1324 Source source = addSource(r''' 1232 Source source = addSource(r'''
1325 class A { 1233 class A {
1326 final int x = 0; 1234 final int x = 0;
1327 A() : x = 1 {} 1235 A() : x = 1 {}
1328 }'''); 1236 }''');
1329 computeLibrarySourceErrors(source);
1330 assertErrors(source, 1237 assertErrors(source,
1331 [StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION]); 1238 [StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION]);
1332 verify([source]); 1239 verify([source]);
1333 } 1240 }
1334 1241
1335 void test_fieldInitializerNotAssignable() { 1242 void test_fieldInitializerNotAssignable() {
1336 Source source = addSource(r''' 1243 Source source = addSource(r'''
1337 class A { 1244 class A {
1338 int x; 1245 int x;
1339 A() : x = ''; 1246 A() : x = '';
1340 }'''); 1247 }''');
1341 computeLibrarySourceErrors(source);
1342 assertErrors(source, [StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE]); 1248 assertErrors(source, [StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE]);
1343 verify([source]); 1249 verify([source]);
1344 } 1250 }
1345 1251
1346 void test_fieldInitializingFormalNotAssignable() { 1252 void test_fieldInitializingFormalNotAssignable() {
1347 Source source = addSource(r''' 1253 Source source = addSource(r'''
1348 class A { 1254 class A {
1349 int x; 1255 int x;
1350 A(String this.x) {} 1256 A(String this.x) {}
1351 }'''); 1257 }''');
1352 computeLibrarySourceErrors(source);
1353 assertErrors( 1258 assertErrors(
1354 source, [StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE]); 1259 source, [StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE]);
1355 verify([source]); 1260 verify([source]);
1356 } 1261 }
1357 1262
1358 /** 1263 /**
1359 * This test doesn't test the FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR code, but tests the 1264 * This test doesn't test the FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR code, but tests the
1360 * FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION code instead. It is provid ed here to show 1265 * FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION code instead. It is provid ed here to show
1361 * coverage over all of the permutations of initializers in constructor declar ations. 1266 * coverage over all of the permutations of initializers in constructor declar ations.
1362 * 1267 *
1363 * Note: FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION covers a subset of 1268 * Note: FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION covers a subset of
1364 * FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR, since it more specific, w e use it instead of 1269 * FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR, since it more specific, w e use it instead of
1365 * the broader code 1270 * the broader code
1366 */ 1271 */
1367 void test_finalInitializedInDeclarationAndConstructor_initializers() { 1272 void test_finalInitializedInDeclarationAndConstructor_initializers() {
1368 Source source = addSource(r''' 1273 Source source = addSource(r'''
1369 class A { 1274 class A {
1370 final x = 0; 1275 final x = 0;
1371 A() : x = 0 {} 1276 A() : x = 0 {}
1372 }'''); 1277 }''');
1373 computeLibrarySourceErrors(source);
1374 assertErrors(source, 1278 assertErrors(source,
1375 [StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION]); 1279 [StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION]);
1376 verify([source]); 1280 verify([source]);
1377 } 1281 }
1378 1282
1379 void test_finalInitializedInDeclarationAndConstructor_initializingFormal() { 1283 void test_finalInitializedInDeclarationAndConstructor_initializingFormal() {
1380 Source source = addSource(r''' 1284 Source source = addSource(r'''
1381 class A { 1285 class A {
1382 final x = 0; 1286 final x = 0;
1383 A(this.x) {} 1287 A(this.x) {}
1384 }'''); 1288 }''');
1385 computeLibrarySourceErrors(source);
1386 assertErrors(source, 1289 assertErrors(source,
1387 [StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR]); 1290 [StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR]);
1388 verify([source]); 1291 verify([source]);
1389 } 1292 }
1390 1293
1391 void test_finalNotInitialized_inConstructor_1() { 1294 void test_finalNotInitialized_inConstructor_1() {
1392 Source source = addSource(r''' 1295 Source source = addSource(r'''
1393 class A { 1296 class A {
1394 final int x; 1297 final int x;
1395 A() {} 1298 A() {}
1396 }'''); 1299 }''');
1397 computeLibrarySourceErrors(source);
1398 assertErrors( 1300 assertErrors(
1399 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1]); 1301 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1]);
1400 verify([source]); 1302 verify([source]);
1401 } 1303 }
1402 1304
1403 void test_finalNotInitialized_inConstructor_2() { 1305 void test_finalNotInitialized_inConstructor_2() {
1404 Source source = addSource(r''' 1306 Source source = addSource(r'''
1405 class A { 1307 class A {
1406 final int a; 1308 final int a;
1407 final int b; 1309 final int b;
1408 A() {} 1310 A() {}
1409 }'''); 1311 }''');
1410 computeLibrarySourceErrors(source);
1411 assertErrors( 1312 assertErrors(
1412 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2]); 1313 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2]);
1413 verify([source]); 1314 verify([source]);
1414 } 1315 }
1415 1316
1416 void test_finalNotInitialized_inConstructor_3() { 1317 void test_finalNotInitialized_inConstructor_3() {
1417 Source source = addSource(r''' 1318 Source source = addSource(r'''
1418 class A { 1319 class A {
1419 final int a; 1320 final int a;
1420 final int b; 1321 final int b;
1421 final int c; 1322 final int c;
1422 A() {} 1323 A() {}
1423 }'''); 1324 }''');
1424 computeLibrarySourceErrors(source);
1425 assertErrors( 1325 assertErrors(
1426 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS]); 1326 source, [StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS]);
1427 verify([source]); 1327 verify([source]);
1428 } 1328 }
1429 1329
1430 void test_finalNotInitialized_instanceField_final() { 1330 void test_finalNotInitialized_instanceField_final() {
1431 Source source = addSource(r''' 1331 Source source = addSource(r'''
1432 class A { 1332 class A {
1433 final F; 1333 final F;
1434 }'''); 1334 }''');
1435 computeLibrarySourceErrors(source);
1436 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); 1335 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]);
1437 verify([source]); 1336 verify([source]);
1438 } 1337 }
1439 1338
1440 void test_finalNotInitialized_instanceField_final_static() { 1339 void test_finalNotInitialized_instanceField_final_static() {
1441 Source source = addSource(r''' 1340 Source source = addSource(r'''
1442 class A { 1341 class A {
1443 static final F; 1342 static final F;
1444 }'''); 1343 }''');
1445 computeLibrarySourceErrors(source);
1446 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); 1344 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]);
1447 verify([source]); 1345 verify([source]);
1448 } 1346 }
1449 1347
1450 void test_finalNotInitialized_library_final() { 1348 void test_finalNotInitialized_library_final() {
1451 Source source = addSource("final F;"); 1349 Source source = addSource("final F;");
1452 computeLibrarySourceErrors(source);
1453 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); 1350 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]);
1454 verify([source]); 1351 verify([source]);
1455 } 1352 }
1456 1353
1457 void test_finalNotInitialized_local_final() { 1354 void test_finalNotInitialized_local_final() {
1458 Source source = addSource(r''' 1355 Source source = addSource(r'''
1459 f() { 1356 f() {
1460 final int x; 1357 final int x;
1461 }'''); 1358 }''');
1462 computeLibrarySourceErrors(source);
1463 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]); 1359 assertErrors(source, [StaticWarningCode.FINAL_NOT_INITIALIZED]);
1464 verify([source]); 1360 verify([source]);
1465 } 1361 }
1466 1362
1467 void test_functionWithoutCall_direct() { 1363 void test_functionWithoutCall_direct() {
1468 Source source = addSource(r''' 1364 Source source = addSource(r'''
1469 class A implements Function { 1365 class A implements Function {
1470 }'''); 1366 }''');
1471 computeLibrarySourceErrors(source);
1472 assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]); 1367 assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]);
1473 verify([source]); 1368 verify([source]);
1474 } 1369 }
1475 1370
1476 void test_functionWithoutCall_indirect_extends() { 1371 void test_functionWithoutCall_indirect_extends() {
1477 Source source = addSource(r''' 1372 Source source = addSource(r'''
1478 abstract class A implements Function { 1373 abstract class A implements Function {
1479 } 1374 }
1480 class B extends A { 1375 class B extends A {
1481 }'''); 1376 }''');
1482 computeLibrarySourceErrors(source);
1483 assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]); 1377 assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]);
1484 verify([source]); 1378 verify([source]);
1485 } 1379 }
1486 1380
1487 void test_functionWithoutCall_indirect_implements() { 1381 void test_functionWithoutCall_indirect_implements() {
1488 Source source = addSource(r''' 1382 Source source = addSource(r'''
1489 abstract class A implements Function { 1383 abstract class A implements Function {
1490 } 1384 }
1491 class B implements A { 1385 class B implements A {
1492 }'''); 1386 }''');
1493 computeLibrarySourceErrors(source);
1494 assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]); 1387 assertErrors(source, [StaticWarningCode.FUNCTION_WITHOUT_CALL]);
1495 verify([source]); 1388 verify([source]);
1496 } 1389 }
1497 1390
1498 void test_importDuplicatedLibraryNamed() { 1391 void test_importDuplicatedLibraryNamed() {
1499 Source source = addSource(r''' 1392 Source source = addSource(r'''
1500 library test; 1393 library test;
1501 import 'lib1.dart'; 1394 import 'lib1.dart';
1502 import 'lib2.dart';'''); 1395 import 'lib2.dart';''');
1503 addNamedSource("/lib1.dart", "library lib;"); 1396 addNamedSource("/lib1.dart", "library lib;");
1504 addNamedSource("/lib2.dart", "library lib;"); 1397 addNamedSource("/lib2.dart", "library lib;");
1505 computeLibrarySourceErrors(source);
1506 assertErrors(source, [ 1398 assertErrors(source, [
1507 StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_NAMED, 1399 StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_NAMED,
1508 HintCode.UNUSED_IMPORT, 1400 HintCode.UNUSED_IMPORT,
1509 HintCode.UNUSED_IMPORT 1401 HintCode.UNUSED_IMPORT
1510 ]); 1402 ]);
1511 verify([source]); 1403 verify([source]);
1512 } 1404 }
1513 1405
1514 void test_importOfNonLibrary() { 1406 void test_importOfNonLibrary() {
1515 resolveWithErrors(<String>[ 1407 resolveWithErrors(<String>[
(...skipping 12 matching lines...) Expand all
1528 void test_inconsistentMethodInheritanceGetterAndMethod() { 1420 void test_inconsistentMethodInheritanceGetterAndMethod() {
1529 Source source = addSource(r''' 1421 Source source = addSource(r'''
1530 abstract class A { 1422 abstract class A {
1531 int x(); 1423 int x();
1532 } 1424 }
1533 abstract class B { 1425 abstract class B {
1534 int get x; 1426 int get x;
1535 } 1427 }
1536 class C implements A, B { 1428 class C implements A, B {
1537 }'''); 1429 }''');
1538 computeLibrarySourceErrors(source);
1539 assertErrors(source, 1430 assertErrors(source,
1540 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]); 1431 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]);
1541 verify([source]); 1432 verify([source]);
1542 } 1433 }
1543 1434
1544 void test_instanceMethodNameCollidesWithSuperclassStatic_field() { 1435 void test_instanceMethodNameCollidesWithSuperclassStatic_field() {
1545 Source source = addSource(r''' 1436 Source source = addSource(r'''
1546 class A { 1437 class A {
1547 static var n; 1438 static var n;
1548 } 1439 }
1549 class B extends A { 1440 class B extends A {
1550 void n() {} 1441 void n() {}
1551 }'''); 1442 }''');
1552 computeLibrarySourceErrors(source);
1553 assertErrors(source, [ 1443 assertErrors(source, [
1554 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1444 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
1555 ]); 1445 ]);
1556 verify([source]); 1446 verify([source]);
1557 } 1447 }
1558 1448
1559 void test_instanceMethodNameCollidesWithSuperclassStatic_field2() { 1449 void test_instanceMethodNameCollidesWithSuperclassStatic_field2() {
1560 Source source = addSource(r''' 1450 Source source = addSource(r'''
1561 class A { 1451 class A {
1562 static var n; 1452 static var n;
1563 } 1453 }
1564 class B extends A { 1454 class B extends A {
1565 } 1455 }
1566 class C extends B { 1456 class C extends B {
1567 void n() {} 1457 void n() {}
1568 }'''); 1458 }''');
1569 computeLibrarySourceErrors(source);
1570 assertErrors(source, [ 1459 assertErrors(source, [
1571 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1460 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
1572 ]); 1461 ]);
1573 verify([source]); 1462 verify([source]);
1574 } 1463 }
1575 1464
1576 void test_instanceMethodNameCollidesWithSuperclassStatic_getter() { 1465 void test_instanceMethodNameCollidesWithSuperclassStatic_getter() {
1577 Source source = addSource(r''' 1466 Source source = addSource(r'''
1578 class A { 1467 class A {
1579 static get n {return 0;} 1468 static get n {return 0;}
1580 } 1469 }
1581 class B extends A { 1470 class B extends A {
1582 void n() {} 1471 void n() {}
1583 }'''); 1472 }''');
1584 computeLibrarySourceErrors(source);
1585 assertErrors(source, [ 1473 assertErrors(source, [
1586 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1474 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
1587 ]); 1475 ]);
1588 verify([source]); 1476 verify([source]);
1589 } 1477 }
1590 1478
1591 void test_instanceMethodNameCollidesWithSuperclassStatic_getter2() { 1479 void test_instanceMethodNameCollidesWithSuperclassStatic_getter2() {
1592 Source source = addSource(r''' 1480 Source source = addSource(r'''
1593 class A { 1481 class A {
1594 static get n {return 0;} 1482 static get n {return 0;}
1595 } 1483 }
1596 class B extends A { 1484 class B extends A {
1597 } 1485 }
1598 class C extends B { 1486 class C extends B {
1599 void n() {} 1487 void n() {}
1600 }'''); 1488 }''');
1601 computeLibrarySourceErrors(source);
1602 assertErrors(source, [ 1489 assertErrors(source, [
1603 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1490 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
1604 ]); 1491 ]);
1605 verify([source]); 1492 verify([source]);
1606 } 1493 }
1607 1494
1608 void test_instanceMethodNameCollidesWithSuperclassStatic_interface() { 1495 void test_instanceMethodNameCollidesWithSuperclassStatic_interface() {
1609 Source source = addSource(r''' 1496 Source source = addSource(r'''
1610 class Base { 1497 class Base {
1611 static foo() {} 1498 static foo() {}
1612 } 1499 }
1613 abstract class Ifc { 1500 abstract class Ifc {
1614 foo(); 1501 foo();
1615 } 1502 }
1616 class C extends Base implements Ifc { 1503 class C extends Base implements Ifc {
1617 foo() {} 1504 foo() {}
1618 } 1505 }
1619 '''); 1506 ''');
1620 computeLibrarySourceErrors(source);
1621 assertErrors(source, [ 1507 assertErrors(source, [
1622 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1508 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
1623 ]); 1509 ]);
1624 verify([source]); 1510 verify([source]);
1625 } 1511 }
1626 1512
1627 void test_instanceMethodNameCollidesWithSuperclassStatic_method() { 1513 void test_instanceMethodNameCollidesWithSuperclassStatic_method() {
1628 Source source = addSource(r''' 1514 Source source = addSource(r'''
1629 class A { 1515 class A {
1630 static n () {} 1516 static n () {}
1631 } 1517 }
1632 class B extends A { 1518 class B extends A {
1633 void n() {} 1519 void n() {}
1634 }'''); 1520 }''');
1635 computeLibrarySourceErrors(source);
1636 assertErrors(source, [ 1521 assertErrors(source, [
1637 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1522 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
1638 ]); 1523 ]);
1639 verify([source]); 1524 verify([source]);
1640 } 1525 }
1641 1526
1642 void test_instanceMethodNameCollidesWithSuperclassStatic_method2() { 1527 void test_instanceMethodNameCollidesWithSuperclassStatic_method2() {
1643 Source source = addSource(r''' 1528 Source source = addSource(r'''
1644 class A { 1529 class A {
1645 static n () {} 1530 static n () {}
1646 } 1531 }
1647 class B extends A { 1532 class B extends A {
1648 } 1533 }
1649 class C extends B { 1534 class C extends B {
1650 void n() {} 1535 void n() {}
1651 }'''); 1536 }''');
1652 computeLibrarySourceErrors(source);
1653 assertErrors(source, [ 1537 assertErrors(source, [
1654 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1538 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
1655 ]); 1539 ]);
1656 verify([source]); 1540 verify([source]);
1657 } 1541 }
1658 1542
1659 void test_instanceMethodNameCollidesWithSuperclassStatic_setter() { 1543 void test_instanceMethodNameCollidesWithSuperclassStatic_setter() {
1660 Source source = addSource(r''' 1544 Source source = addSource(r'''
1661 class A { 1545 class A {
1662 static set n(int x) {} 1546 static set n(int x) {}
1663 } 1547 }
1664 class B extends A { 1548 class B extends A {
1665 void n() {} 1549 void n() {}
1666 }'''); 1550 }''');
1667 computeLibrarySourceErrors(source);
1668 assertErrors(source, [ 1551 assertErrors(source, [
1669 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1552 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
1670 ]); 1553 ]);
1671 verify([source]); 1554 verify([source]);
1672 } 1555 }
1673 1556
1674 void test_instanceMethodNameCollidesWithSuperclassStatic_setter2() { 1557 void test_instanceMethodNameCollidesWithSuperclassStatic_setter2() {
1675 Source source = addSource(r''' 1558 Source source = addSource(r'''
1676 class A { 1559 class A {
1677 static set n(int x) {} 1560 static set n(int x) {}
1678 } 1561 }
1679 class B extends A { 1562 class B extends A {
1680 } 1563 }
1681 class C extends B { 1564 class C extends B {
1682 void n() {} 1565 void n() {}
1683 }'''); 1566 }''');
1684 computeLibrarySourceErrors(source);
1685 assertErrors(source, [ 1567 assertErrors(source, [
1686 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 1568 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
1687 ]); 1569 ]);
1688 verify([source]); 1570 verify([source]);
1689 } 1571 }
1690 1572
1691 void test_invalidGetterOverrideReturnType() { 1573 void test_invalidGetterOverrideReturnType() {
1692 Source source = addSource(r''' 1574 Source source = addSource(r'''
1693 class A { 1575 class A {
1694 int get g { return 0; } 1576 int get g { return 0; }
1695 } 1577 }
1696 class B extends A { 1578 class B extends A {
1697 String get g { return 'a'; } 1579 String get g { return 'a'; }
1698 }'''); 1580 }''');
1699 computeLibrarySourceErrors(source);
1700 assertErrors( 1581 assertErrors(
1701 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]); 1582 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]);
1702 verify([source]); 1583 verify([source]);
1703 } 1584 }
1704 1585
1705 void test_invalidGetterOverrideReturnType_implicit() { 1586 void test_invalidGetterOverrideReturnType_implicit() {
1706 Source source = addSource(r''' 1587 Source source = addSource(r'''
1707 class A { 1588 class A {
1708 String f; 1589 String f;
1709 } 1590 }
1710 class B extends A { 1591 class B extends A {
1711 int f; 1592 int f;
1712 }'''); 1593 }''');
1713 computeLibrarySourceErrors(source);
1714 assertErrors(source, [ 1594 assertErrors(source, [
1715 StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, 1595 StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE,
1716 StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE 1596 StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE
1717 ]); 1597 ]);
1718 verify([source]); 1598 verify([source]);
1719 } 1599 }
1720 1600
1721 void test_invalidGetterOverrideReturnType_twoInterfaces() { 1601 void test_invalidGetterOverrideReturnType_twoInterfaces() {
1722 // test from language/override_inheritance_field_test_11.dart 1602 // test from language/override_inheritance_field_test_11.dart
1723 Source source = addSource(r''' 1603 Source source = addSource(r'''
1724 abstract class I { 1604 abstract class I {
1725 int get getter => null; 1605 int get getter => null;
1726 } 1606 }
1727 abstract class J { 1607 abstract class J {
1728 num get getter => null; 1608 num get getter => null;
1729 } 1609 }
1730 abstract class A implements I, J {} 1610 abstract class A implements I, J {}
1731 class B extends A { 1611 class B extends A {
1732 String get getter => null; 1612 String get getter => null;
1733 }'''); 1613 }''');
1734 computeLibrarySourceErrors(source);
1735 assertErrors( 1614 assertErrors(
1736 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]); 1615 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]);
1737 verify([source]); 1616 verify([source]);
1738 } 1617 }
1739 1618
1740 void test_invalidGetterOverrideReturnType_twoInterfaces_conflicting() { 1619 void test_invalidGetterOverrideReturnType_twoInterfaces_conflicting() {
1741 Source source = addSource(r''' 1620 Source source = addSource(r'''
1742 abstract class I<U> { 1621 abstract class I<U> {
1743 U get g => null; 1622 U get g => null;
1744 } 1623 }
1745 abstract class J<V> { 1624 abstract class J<V> {
1746 V get g => null; 1625 V get g => null;
1747 } 1626 }
1748 class B implements I<int>, J<String> { 1627 class B implements I<int>, J<String> {
1749 double get g => null; 1628 double get g => null;
1750 }'''); 1629 }''');
1751 computeLibrarySourceErrors(source);
1752 assertErrors( 1630 assertErrors(
1753 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]); 1631 source, [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE]);
1754 verify([source]); 1632 verify([source]);
1755 } 1633 }
1756 1634
1757 void test_invalidMethodOverrideNamedParamType() { 1635 void test_invalidMethodOverrideNamedParamType() {
1758 Source source = addSource(r''' 1636 Source source = addSource(r'''
1759 class A { 1637 class A {
1760 m({int a}) {} 1638 m({int a}) {}
1761 } 1639 }
1762 class B implements A { 1640 class B implements A {
1763 m({String a}) {} 1641 m({String a}) {}
1764 }'''); 1642 }''');
1765 computeLibrarySourceErrors(source);
1766 assertErrors( 1643 assertErrors(
1767 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE]); 1644 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE]);
1768 verify([source]); 1645 verify([source]);
1769 } 1646 }
1770 1647
1771 void test_invalidMethodOverrideNormalParamType_interface() { 1648 void test_invalidMethodOverrideNormalParamType_interface() {
1772 Source source = addSource(r''' 1649 Source source = addSource(r'''
1773 class A { 1650 class A {
1774 m(int a) {} 1651 m(int a) {}
1775 } 1652 }
1776 class B implements A { 1653 class B implements A {
1777 m(String a) {} 1654 m(String a) {}
1778 }'''); 1655 }''');
1779 computeLibrarySourceErrors(source);
1780 assertErrors( 1656 assertErrors(
1781 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); 1657 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
1782 verify([source]); 1658 verify([source]);
1783 } 1659 }
1784 1660
1785 void test_invalidMethodOverrideNormalParamType_superclass() { 1661 void test_invalidMethodOverrideNormalParamType_superclass() {
1786 Source source = addSource(r''' 1662 Source source = addSource(r'''
1787 class A { 1663 class A {
1788 m(int a) {} 1664 m(int a) {}
1789 } 1665 }
1790 class B extends A { 1666 class B extends A {
1791 m(String a) {} 1667 m(String a) {}
1792 }'''); 1668 }''');
1793 computeLibrarySourceErrors(source);
1794 assertErrors( 1669 assertErrors(
1795 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); 1670 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
1796 verify([source]); 1671 verify([source]);
1797 } 1672 }
1798 1673
1799 void test_invalidMethodOverrideNormalParamType_superclass_interface() { 1674 void test_invalidMethodOverrideNormalParamType_superclass_interface() {
1800 Source source = addSource(r''' 1675 Source source = addSource(r'''
1801 abstract class I<U> { 1676 abstract class I<U> {
1802 m(U u) => null; 1677 m(U u) => null;
1803 } 1678 }
1804 abstract class J<V> { 1679 abstract class J<V> {
1805 m(V v) => null; 1680 m(V v) => null;
1806 } 1681 }
1807 class B extends I<int> implements J<String> { 1682 class B extends I<int> implements J<String> {
1808 m(double d) {} 1683 m(double d) {}
1809 }'''); 1684 }''');
1810 computeLibrarySourceErrors(source);
1811 assertErrors( 1685 assertErrors(
1812 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); 1686 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
1813 verify([source]); 1687 verify([source]);
1814 } 1688 }
1815 1689
1816 void test_invalidMethodOverrideNormalParamType_twoInterfaces() { 1690 void test_invalidMethodOverrideNormalParamType_twoInterfaces() {
1817 Source source = addSource(r''' 1691 Source source = addSource(r'''
1818 abstract class I { 1692 abstract class I {
1819 m(int n); 1693 m(int n);
1820 } 1694 }
1821 abstract class J { 1695 abstract class J {
1822 m(num n); 1696 m(num n);
1823 } 1697 }
1824 abstract class A implements I, J {} 1698 abstract class A implements I, J {}
1825 class B extends A { 1699 class B extends A {
1826 m(String n) {} 1700 m(String n) {}
1827 }'''); 1701 }''');
1828 computeLibrarySourceErrors(source);
1829 assertErrors( 1702 assertErrors(
1830 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); 1703 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
1831 verify([source]); 1704 verify([source]);
1832 } 1705 }
1833 1706
1834 void test_invalidMethodOverrideNormalParamType_twoInterfaces_conflicting() { 1707 void test_invalidMethodOverrideNormalParamType_twoInterfaces_conflicting() {
1835 // language/override_inheritance_generic_test/08 1708 // language/override_inheritance_generic_test/08
1836 Source source = addSource(r''' 1709 Source source = addSource(r'''
1837 abstract class I<U> { 1710 abstract class I<U> {
1838 m(U u) => null; 1711 m(U u) => null;
1839 } 1712 }
1840 abstract class J<V> { 1713 abstract class J<V> {
1841 m(V v) => null; 1714 m(V v) => null;
1842 } 1715 }
1843 class B implements I<int>, J<String> { 1716 class B implements I<int>, J<String> {
1844 m(double d) {} 1717 m(double d) {}
1845 }'''); 1718 }''');
1846 computeLibrarySourceErrors(source);
1847 assertErrors( 1719 assertErrors(
1848 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]); 1720 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE]);
1849 verify([source]); 1721 verify([source]);
1850 } 1722 }
1851 1723
1852 void test_invalidMethodOverrideOptionalParamType() { 1724 void test_invalidMethodOverrideOptionalParamType() {
1853 Source source = addSource(r''' 1725 Source source = addSource(r'''
1854 class A { 1726 class A {
1855 m([int a]) {} 1727 m([int a]) {}
1856 } 1728 }
1857 class B implements A { 1729 class B implements A {
1858 m([String a]) {} 1730 m([String a]) {}
1859 }'''); 1731 }''');
1860 computeLibrarySourceErrors(source);
1861 assertErrors(source, 1732 assertErrors(source,
1862 [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]); 1733 [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]);
1863 verify([source]); 1734 verify([source]);
1864 } 1735 }
1865 1736
1866 void test_invalidMethodOverrideOptionalParamType_twoInterfaces() { 1737 void test_invalidMethodOverrideOptionalParamType_twoInterfaces() {
1867 Source source = addSource(r''' 1738 Source source = addSource(r'''
1868 abstract class I { 1739 abstract class I {
1869 m([int n]); 1740 m([int n]);
1870 } 1741 }
1871 abstract class J { 1742 abstract class J {
1872 m([num n]); 1743 m([num n]);
1873 } 1744 }
1874 abstract class A implements I, J {} 1745 abstract class A implements I, J {}
1875 class B extends A { 1746 class B extends A {
1876 m([String n]) {} 1747 m([String n]) {}
1877 }'''); 1748 }''');
1878 computeLibrarySourceErrors(source);
1879 assertErrors(source, 1749 assertErrors(source,
1880 [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]); 1750 [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE]);
1881 verify([source]); 1751 verify([source]);
1882 } 1752 }
1883 1753
1884 void test_invalidMethodOverrideReturnType_interface() { 1754 void test_invalidMethodOverrideReturnType_interface() {
1885 Source source = addSource(r''' 1755 Source source = addSource(r'''
1886 class A { 1756 class A {
1887 int m() { return 0; } 1757 int m() { return 0; }
1888 } 1758 }
1889 class B implements A { 1759 class B implements A {
1890 String m() { return 'a'; } 1760 String m() { return 'a'; }
1891 }'''); 1761 }''');
1892 computeLibrarySourceErrors(source);
1893 assertErrors( 1762 assertErrors(
1894 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); 1763 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
1895 verify([source]); 1764 verify([source]);
1896 } 1765 }
1897 1766
1898 void test_invalidMethodOverrideReturnType_interface_grandparent() { 1767 void test_invalidMethodOverrideReturnType_interface_grandparent() {
1899 Source source = addSource(r''' 1768 Source source = addSource(r'''
1900 abstract class A { 1769 abstract class A {
1901 int m(); 1770 int m();
1902 } 1771 }
1903 abstract class B implements A { 1772 abstract class B implements A {
1904 } 1773 }
1905 class C implements B { 1774 class C implements B {
1906 String m() { return 'a'; } 1775 String m() { return 'a'; }
1907 }'''); 1776 }''');
1908 computeLibrarySourceErrors(source);
1909 assertErrors( 1777 assertErrors(
1910 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); 1778 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
1911 verify([source]); 1779 verify([source]);
1912 } 1780 }
1913 1781
1914 void test_invalidMethodOverrideReturnType_mixin() { 1782 void test_invalidMethodOverrideReturnType_mixin() {
1915 Source source = addSource(r''' 1783 Source source = addSource(r'''
1916 class A { 1784 class A {
1917 int m() { return 0; } 1785 int m() { return 0; }
1918 } 1786 }
1919 class B extends Object with A { 1787 class B extends Object with A {
1920 String m() { return 'a'; } 1788 String m() { return 'a'; }
1921 }'''); 1789 }''');
1922 computeLibrarySourceErrors(source);
1923 assertErrors( 1790 assertErrors(
1924 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); 1791 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
1925 verify([source]); 1792 verify([source]);
1926 } 1793 }
1927 1794
1928 void test_invalidMethodOverrideReturnType_superclass() { 1795 void test_invalidMethodOverrideReturnType_superclass() {
1929 Source source = addSource(r''' 1796 Source source = addSource(r'''
1930 class A { 1797 class A {
1931 int m() { return 0; } 1798 int m() { return 0; }
1932 } 1799 }
1933 class B extends A { 1800 class B extends A {
1934 String m() { return 'a'; } 1801 String m() { return 'a'; }
1935 }'''); 1802 }''');
1936 computeLibrarySourceErrors(source);
1937 assertErrors( 1803 assertErrors(
1938 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); 1804 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
1939 verify([source]); 1805 verify([source]);
1940 } 1806 }
1941 1807
1942 void test_invalidMethodOverrideReturnType_superclass_grandparent() { 1808 void test_invalidMethodOverrideReturnType_superclass_grandparent() {
1943 Source source = addSource(r''' 1809 Source source = addSource(r'''
1944 class A { 1810 class A {
1945 int m() { return 0; } 1811 int m() { return 0; }
1946 } 1812 }
1947 class B extends A { 1813 class B extends A {
1948 } 1814 }
1949 class C extends B { 1815 class C extends B {
1950 String m() { return 'a'; } 1816 String m() { return 'a'; }
1951 }'''); 1817 }''');
1952 computeLibrarySourceErrors(source);
1953 assertErrors( 1818 assertErrors(
1954 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); 1819 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
1955 verify([source]); 1820 verify([source]);
1956 } 1821 }
1957 1822
1958 void test_invalidMethodOverrideReturnType_twoInterfaces() { 1823 void test_invalidMethodOverrideReturnType_twoInterfaces() {
1959 Source source = addSource(r''' 1824 Source source = addSource(r'''
1960 abstract class I { 1825 abstract class I {
1961 int m(); 1826 int m();
1962 } 1827 }
1963 abstract class J { 1828 abstract class J {
1964 num m(); 1829 num m();
1965 } 1830 }
1966 abstract class A implements I, J {} 1831 abstract class A implements I, J {}
1967 class B extends A { 1832 class B extends A {
1968 String m() => ''; 1833 String m() => '';
1969 }'''); 1834 }''');
1970 computeLibrarySourceErrors(source);
1971 assertErrors( 1835 assertErrors(
1972 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); 1836 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
1973 verify([source]); 1837 verify([source]);
1974 } 1838 }
1975 1839
1976 void test_invalidMethodOverrideReturnType_void() { 1840 void test_invalidMethodOverrideReturnType_void() {
1977 Source source = addSource(r''' 1841 Source source = addSource(r'''
1978 class A { 1842 class A {
1979 int m() { return 0; } 1843 int m() { return 0; }
1980 } 1844 }
1981 class B extends A { 1845 class B extends A {
1982 void m() {} 1846 void m() {}
1983 }'''); 1847 }''');
1984 computeLibrarySourceErrors(source);
1985 assertErrors( 1848 assertErrors(
1986 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]); 1849 source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE]);
1987 verify([source]); 1850 verify([source]);
1988 } 1851 }
1989 1852
1990 void test_invalidOverride_defaultOverridesNonDefault() { 1853 void test_invalidOverride_defaultOverridesNonDefault() {
1991 // If the base class provided an explicit value for a default parameter, 1854 // If the base class provided an explicit value for a default parameter,
1992 // then it is a static warning for the derived class to provide a different 1855 // then it is a static warning for the derived class to provide a different
1993 // value, even if implicitly. 1856 // value, even if implicitly.
1994 Source source = addSource(r''' 1857 Source source = addSource(r'''
1995 class A { 1858 class A {
1996 foo([x = 1]) {} 1859 foo([x = 1]) {}
1997 } 1860 }
1998 class B extends A { 1861 class B extends A {
1999 foo([x]) {} 1862 foo([x]) {}
2000 } 1863 }
2001 '''); 1864 ''');
2002 computeLibrarySourceErrors(source);
2003 assertErrors(source, [ 1865 assertErrors(source, [
2004 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL 1866 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL
2005 ]); 1867 ]);
2006 verify([source]); 1868 verify([source]);
2007 } 1869 }
2008 1870
2009 void test_invalidOverride_defaultOverridesNonDefault_named() { 1871 void test_invalidOverride_defaultOverridesNonDefault_named() {
2010 // If the base class provided an explicit value for a default parameter, 1872 // If the base class provided an explicit value for a default parameter,
2011 // then it is a static warning for the derived class to provide a different 1873 // then it is a static warning for the derived class to provide a different
2012 // value, even if implicitly. 1874 // value, even if implicitly.
2013 Source source = addSource(r''' 1875 Source source = addSource(r'''
2014 class A { 1876 class A {
2015 foo({x: 1}) {} 1877 foo({x: 1}) {}
2016 } 1878 }
2017 class B extends A { 1879 class B extends A {
2018 foo({x}) {} 1880 foo({x}) {}
2019 } 1881 }
2020 '''); 1882 ''');
2021 computeLibrarySourceErrors(source);
2022 assertErrors(source, 1883 assertErrors(source,
2023 [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]); 1884 [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]);
2024 verify([source]); 1885 verify([source]);
2025 } 1886 }
2026 1887
2027 void test_invalidOverride_defaultOverridesNonDefaultNull() { 1888 void test_invalidOverride_defaultOverridesNonDefaultNull() {
2028 // If the base class provided an explicit null value for a default 1889 // If the base class provided an explicit null value for a default
2029 // parameter, then it is ok for the derived class to let the default value 1890 // parameter, then it is ok for the derived class to let the default value
2030 // be implicit, because the implicit default value of null matches the 1891 // be implicit, because the implicit default value of null matches the
2031 // explicit default value of null. 1892 // explicit default value of null.
2032 Source source = addSource(r''' 1893 Source source = addSource(r'''
2033 class A { 1894 class A {
2034 foo([x = null]) {} 1895 foo([x = null]) {}
2035 } 1896 }
2036 class B extends A { 1897 class B extends A {
2037 foo([x]) {} 1898 foo([x]) {}
2038 } 1899 }
2039 '''); 1900 ''');
2040 computeLibrarySourceErrors(source);
2041 assertNoErrors(source); 1901 assertNoErrors(source);
2042 verify([source]); 1902 verify([source]);
2043 } 1903 }
2044 1904
2045 void test_invalidOverride_defaultOverridesNonDefaultNull_named() { 1905 void test_invalidOverride_defaultOverridesNonDefaultNull_named() {
2046 // If the base class provided an explicit null value for a default 1906 // If the base class provided an explicit null value for a default
2047 // parameter, then it is ok for the derived class to let the default value 1907 // parameter, then it is ok for the derived class to let the default value
2048 // be implicit, because the implicit default value of null matches the 1908 // be implicit, because the implicit default value of null matches the
2049 // explicit default value of null. 1909 // explicit default value of null.
2050 Source source = addSource(r''' 1910 Source source = addSource(r'''
2051 class A { 1911 class A {
2052 foo({x: null}) {} 1912 foo({x: null}) {}
2053 } 1913 }
2054 class B extends A { 1914 class B extends A {
2055 foo({x}) {} 1915 foo({x}) {}
2056 } 1916 }
2057 '''); 1917 ''');
2058 computeLibrarySourceErrors(source);
2059 assertNoErrors(source); 1918 assertNoErrors(source);
2060 verify([source]); 1919 verify([source]);
2061 } 1920 }
2062 1921
2063 void test_invalidOverride_nonDefaultOverridesDefault() { 1922 void test_invalidOverride_nonDefaultOverridesDefault() {
2064 // If the base class lets the default parameter be implicit, then it is ok 1923 // If the base class lets the default parameter be implicit, then it is ok
2065 // for the derived class to provide an explicit default value, even if it's 1924 // for the derived class to provide an explicit default value, even if it's
2066 // not null. 1925 // not null.
2067 Source source = addSource(r''' 1926 Source source = addSource(r'''
2068 class A { 1927 class A {
2069 foo([x]) {} 1928 foo([x]) {}
2070 } 1929 }
2071 class B extends A { 1930 class B extends A {
2072 foo([x = 1]) {} 1931 foo([x = 1]) {}
2073 } 1932 }
2074 '''); 1933 ''');
2075 computeLibrarySourceErrors(source);
2076 assertNoErrors(source); 1934 assertNoErrors(source);
2077 verify([source]); 1935 verify([source]);
2078 } 1936 }
2079 1937
2080 void test_invalidOverride_nonDefaultOverridesDefault_named() { 1938 void test_invalidOverride_nonDefaultOverridesDefault_named() {
2081 // If the base class lets the default parameter be implicit, then it is ok 1939 // If the base class lets the default parameter be implicit, then it is ok
2082 // for the derived class to provide an explicit default value, even if it's 1940 // for the derived class to provide an explicit default value, even if it's
2083 // not null. 1941 // not null.
2084 Source source = addSource(r''' 1942 Source source = addSource(r'''
2085 class A { 1943 class A {
2086 foo({x}) {} 1944 foo({x}) {}
2087 } 1945 }
2088 class B extends A { 1946 class B extends A {
2089 foo({x: 1}) {} 1947 foo({x: 1}) {}
2090 } 1948 }
2091 '''); 1949 ''');
2092 computeLibrarySourceErrors(source);
2093 assertNoErrors(source); 1950 assertNoErrors(source);
2094 verify([source]); 1951 verify([source]);
2095 } 1952 }
2096 1953
2097 void test_invalidOverrideDifferentDefaultValues_named() { 1954 void test_invalidOverrideDifferentDefaultValues_named() {
2098 Source source = addSource(r''' 1955 Source source = addSource(r'''
2099 class A { 1956 class A {
2100 m({int p : 0}) {} 1957 m({int p : 0}) {}
2101 } 1958 }
2102 class B extends A { 1959 class B extends A {
2103 m({int p : 1}) {} 1960 m({int p : 1}) {}
2104 }'''); 1961 }''');
2105 computeLibrarySourceErrors(source);
2106 assertErrors(source, 1962 assertErrors(source,
2107 [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]); 1963 [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]);
2108 verify([source]); 1964 verify([source]);
2109 } 1965 }
2110 1966
2111 void test_invalidOverrideDifferentDefaultValues_positional() { 1967 void test_invalidOverrideDifferentDefaultValues_positional() {
2112 Source source = addSource(r''' 1968 Source source = addSource(r'''
2113 class A { 1969 class A {
2114 m([int p = 0]) {} 1970 m([int p = 0]) {}
2115 } 1971 }
2116 class B extends A { 1972 class B extends A {
2117 m([int p = 1]) {} 1973 m([int p = 1]) {}
2118 }'''); 1974 }''');
2119 computeLibrarySourceErrors(source);
2120 assertErrors(source, [ 1975 assertErrors(source, [
2121 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL 1976 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL
2122 ]); 1977 ]);
2123 verify([source]); 1978 verify([source]);
2124 } 1979 }
2125 1980
2126 void test_invalidOverrideNamed_fewerNamedParameters() { 1981 void test_invalidOverrideNamed_fewerNamedParameters() {
2127 Source source = addSource(r''' 1982 Source source = addSource(r'''
2128 class A { 1983 class A {
2129 m({a, b}) {} 1984 m({a, b}) {}
2130 } 1985 }
2131 class B extends A { 1986 class B extends A {
2132 m({a}) {} 1987 m({a}) {}
2133 }'''); 1988 }''');
2134 computeLibrarySourceErrors(source);
2135 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]); 1989 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]);
2136 verify([source]); 1990 verify([source]);
2137 } 1991 }
2138 1992
2139 void test_invalidOverrideNamed_missingNamedParameter() { 1993 void test_invalidOverrideNamed_missingNamedParameter() {
2140 Source source = addSource(r''' 1994 Source source = addSource(r'''
2141 class A { 1995 class A {
2142 m({a, b}) {} 1996 m({a, b}) {}
2143 } 1997 }
2144 class B extends A { 1998 class B extends A {
2145 m({a, c}) {} 1999 m({a, c}) {}
2146 }'''); 2000 }''');
2147 computeLibrarySourceErrors(source);
2148 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]); 2001 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_NAMED]);
2149 verify([source]); 2002 verify([source]);
2150 } 2003 }
2151 2004
2152 void test_invalidOverridePositional_optional() { 2005 void test_invalidOverridePositional_optional() {
2153 Source source = addSource(r''' 2006 Source source = addSource(r'''
2154 class A { 2007 class A {
2155 m([a, b]) {} 2008 m([a, b]) {}
2156 } 2009 }
2157 class B extends A { 2010 class B extends A {
2158 m([a]) {} 2011 m([a]) {}
2159 }'''); 2012 }''');
2160 computeLibrarySourceErrors(source);
2161 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]); 2013 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]);
2162 verify([source]); 2014 verify([source]);
2163 } 2015 }
2164 2016
2165 void test_invalidOverridePositional_optionalAndRequired() { 2017 void test_invalidOverridePositional_optionalAndRequired() {
2166 Source source = addSource(r''' 2018 Source source = addSource(r'''
2167 class A { 2019 class A {
2168 m(a, b, [c, d]) {} 2020 m(a, b, [c, d]) {}
2169 } 2021 }
2170 class B extends A { 2022 class B extends A {
2171 m(a, b, [c]) {} 2023 m(a, b, [c]) {}
2172 }'''); 2024 }''');
2173 computeLibrarySourceErrors(source);
2174 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]); 2025 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]);
2175 verify([source]); 2026 verify([source]);
2176 } 2027 }
2177 2028
2178 void test_invalidOverridePositional_optionalAndRequired2() { 2029 void test_invalidOverridePositional_optionalAndRequired2() {
2179 Source source = addSource(r''' 2030 Source source = addSource(r'''
2180 class A { 2031 class A {
2181 m(a, b, [c, d]) {} 2032 m(a, b, [c, d]) {}
2182 } 2033 }
2183 class B extends A { 2034 class B extends A {
2184 m(a, [c, d]) {} 2035 m(a, [c, d]) {}
2185 }'''); 2036 }''');
2186 computeLibrarySourceErrors(source);
2187 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]); 2037 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_POSITIONAL]);
2188 verify([source]); 2038 verify([source]);
2189 } 2039 }
2190 2040
2191 void test_invalidOverrideRequired() { 2041 void test_invalidOverrideRequired() {
2192 Source source = addSource(r''' 2042 Source source = addSource(r'''
2193 class A { 2043 class A {
2194 m(a) {} 2044 m(a) {}
2195 } 2045 }
2196 class B extends A { 2046 class B extends A {
2197 m(a, b) {} 2047 m(a, b) {}
2198 }'''); 2048 }''');
2199 computeLibrarySourceErrors(source);
2200 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_REQUIRED]); 2049 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_REQUIRED]);
2201 verify([source]); 2050 verify([source]);
2202 } 2051 }
2203 2052
2204 void test_invalidSetterOverrideNormalParamType() { 2053 void test_invalidSetterOverrideNormalParamType() {
2205 Source source = addSource(r''' 2054 Source source = addSource(r'''
2206 class A { 2055 class A {
2207 void set s(int v) {} 2056 void set s(int v) {}
2208 } 2057 }
2209 class B extends A { 2058 class B extends A {
2210 void set s(String v) {} 2059 void set s(String v) {}
2211 }'''); 2060 }''');
2212 computeLibrarySourceErrors(source);
2213 assertErrors( 2061 assertErrors(
2214 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); 2062 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
2215 verify([source]); 2063 verify([source]);
2216 } 2064 }
2217 2065
2218 void test_invalidSetterOverrideNormalParamType_superclass_interface() { 2066 void test_invalidSetterOverrideNormalParamType_superclass_interface() {
2219 Source source = addSource(r''' 2067 Source source = addSource(r'''
2220 abstract class I { 2068 abstract class I {
2221 set setter14(int _) => null; 2069 set setter14(int _) => null;
2222 } 2070 }
2223 abstract class J { 2071 abstract class J {
2224 set setter14(num _) => null; 2072 set setter14(num _) => null;
2225 } 2073 }
2226 abstract class A extends I implements J {} 2074 abstract class A extends I implements J {}
2227 class B extends A { 2075 class B extends A {
2228 set setter14(String _) => null; 2076 set setter14(String _) => null;
2229 }'''); 2077 }''');
2230 computeLibrarySourceErrors(source);
2231 assertErrors( 2078 assertErrors(
2232 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); 2079 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
2233 verify([source]); 2080 verify([source]);
2234 } 2081 }
2235 2082
2236 void test_invalidSetterOverrideNormalParamType_twoInterfaces() { 2083 void test_invalidSetterOverrideNormalParamType_twoInterfaces() {
2237 // test from language/override_inheritance_field_test_34.dart 2084 // test from language/override_inheritance_field_test_34.dart
2238 Source source = addSource(r''' 2085 Source source = addSource(r'''
2239 abstract class I { 2086 abstract class I {
2240 set setter14(int _) => null; 2087 set setter14(int _) => null;
2241 } 2088 }
2242 abstract class J { 2089 abstract class J {
2243 set setter14(num _) => null; 2090 set setter14(num _) => null;
2244 } 2091 }
2245 abstract class A implements I, J {} 2092 abstract class A implements I, J {}
2246 class B extends A { 2093 class B extends A {
2247 set setter14(String _) => null; 2094 set setter14(String _) => null;
2248 }'''); 2095 }''');
2249 computeLibrarySourceErrors(source);
2250 assertErrors( 2096 assertErrors(
2251 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); 2097 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
2252 verify([source]); 2098 verify([source]);
2253 } 2099 }
2254 2100
2255 void test_invalidSetterOverrideNormalParamType_twoInterfaces_conflicting() { 2101 void test_invalidSetterOverrideNormalParamType_twoInterfaces_conflicting() {
2256 Source source = addSource(r''' 2102 Source source = addSource(r'''
2257 abstract class I<U> { 2103 abstract class I<U> {
2258 set s(U u) {} 2104 set s(U u) {}
2259 } 2105 }
2260 abstract class J<V> { 2106 abstract class J<V> {
2261 set s(V v) {} 2107 set s(V v) {}
2262 } 2108 }
2263 class B implements I<int>, J<String> { 2109 class B implements I<int>, J<String> {
2264 set s(double d) {} 2110 set s(double d) {}
2265 }'''); 2111 }''');
2266 computeLibrarySourceErrors(source);
2267 assertErrors( 2112 assertErrors(
2268 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]); 2113 source, [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE]);
2269 verify([source]); 2114 verify([source]);
2270 } 2115 }
2271 2116
2272 void test_listElementTypeNotAssignable() { 2117 void test_listElementTypeNotAssignable() {
2273 Source source = addSource("var v = <String> [42];"); 2118 Source source = addSource("var v = <String> [42];");
2274 computeLibrarySourceErrors(source);
2275 assertErrors(source, [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]); 2119 assertErrors(source, [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]);
2276 verify([source]); 2120 verify([source]);
2277 } 2121 }
2278 2122
2279 void test_mapKeyTypeNotAssignable() { 2123 void test_mapKeyTypeNotAssignable() {
2280 Source source = addSource("var v = <String, int > {1 : 2};"); 2124 Source source = addSource("var v = <String, int > {1 : 2};");
2281 computeLibrarySourceErrors(source);
2282 assertErrors(source, [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE]); 2125 assertErrors(source, [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE]);
2283 verify([source]); 2126 verify([source]);
2284 } 2127 }
2285 2128
2286 void test_mapValueTypeNotAssignable() { 2129 void test_mapValueTypeNotAssignable() {
2287 Source source = addSource("var v = <String, String> {'a' : 2};"); 2130 Source source = addSource("var v = <String, String> {'a' : 2};");
2288 computeLibrarySourceErrors(source);
2289 assertErrors(source, [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]); 2131 assertErrors(source, [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]);
2290 verify([source]); 2132 verify([source]);
2291 } 2133 }
2292 2134
2293 void test_mismatchedAccessorTypes_class() { 2135 void test_mismatchedAccessorTypes_class() {
2294 Source source = addSource(r''' 2136 Source source = addSource(r'''
2295 class A { 2137 class A {
2296 int get g { return 0; } 2138 int get g { return 0; }
2297 set g(String v) {} 2139 set g(String v) {}
2298 }'''); 2140 }''');
2299 computeLibrarySourceErrors(source);
2300 assertErrors( 2141 assertErrors(
2301 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); 2142 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]);
2302 verify([source]); 2143 verify([source]);
2303 } 2144 }
2304 2145
2305 void test_mismatchedAccessorTypes_getterAndSuperSetter() { 2146 void test_mismatchedAccessorTypes_getterAndSuperSetter() {
2306 Source source = addSource(r''' 2147 Source source = addSource(r'''
2307 class A { 2148 class A {
2308 int get g { return 0; } 2149 int get g { return 0; }
2309 } 2150 }
2310 class B extends A { 2151 class B extends A {
2311 set g(String v) {} 2152 set g(String v) {}
2312 }'''); 2153 }''');
2313 computeLibrarySourceErrors(source);
2314 assertErrors(source, 2154 assertErrors(source,
2315 [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE]); 2155 [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE]);
2316 verify([source]); 2156 verify([source]);
2317 } 2157 }
2318 2158
2319 void test_mismatchedAccessorTypes_setterAndSuperGetter() { 2159 void test_mismatchedAccessorTypes_setterAndSuperGetter() {
2320 Source source = addSource(r''' 2160 Source source = addSource(r'''
2321 class A { 2161 class A {
2322 set g(int v) {} 2162 set g(int v) {}
2323 } 2163 }
2324 class B extends A { 2164 class B extends A {
2325 String get g { return ''; } 2165 String get g { return ''; }
2326 }'''); 2166 }''');
2327 computeLibrarySourceErrors(source);
2328 assertErrors(source, 2167 assertErrors(source,
2329 [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE]); 2168 [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE]);
2330 verify([source]); 2169 verify([source]);
2331 } 2170 }
2332 2171
2333 void test_mismatchedAccessorTypes_topLevel() { 2172 void test_mismatchedAccessorTypes_topLevel() {
2334 Source source = addSource(r''' 2173 Source source = addSource(r'''
2335 int get g { return 0; } 2174 int get g { return 0; }
2336 set g(String v) {}'''); 2175 set g(String v) {}''');
2337 computeLibrarySourceErrors(source);
2338 assertErrors( 2176 assertErrors(
2339 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); 2177 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]);
2340 verify([source]); 2178 verify([source]);
2341 } 2179 }
2342 2180
2343 void test_missingEnumConstantInSwitch() { 2181 void test_missingEnumConstantInSwitch() {
2344 Source source = addSource(r''' 2182 Source source = addSource(r'''
2345 enum E { ONE, TWO, THREE, FOUR } 2183 enum E { ONE, TWO, THREE, FOUR }
2346 bool odd(E e) { 2184 bool odd(E e) {
2347 switch (e) { 2185 switch (e) {
2348 case E.ONE: 2186 case E.ONE:
2349 case E.THREE: return true; 2187 case E.THREE: return true;
2350 } 2188 }
2351 return false; 2189 return false;
2352 }'''); 2190 }''');
2353 computeLibrarySourceErrors(source);
2354 assertErrors(source, [ 2191 assertErrors(source, [
2355 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH, 2192 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH,
2356 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH 2193 StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH
2357 ]); 2194 ]);
2358 verify([source]); 2195 verify([source]);
2359 } 2196 }
2360 2197
2361 void test_mixedReturnTypes_localFunction() { 2198 void test_mixedReturnTypes_localFunction() {
2362 Source source = addSource(r''' 2199 Source source = addSource(r'''
2363 class C { 2200 class C {
2364 m(int x) { 2201 m(int x) {
2365 return (int y) { 2202 return (int y) {
2366 if (y < 0) { 2203 if (y < 0) {
2367 return; 2204 return;
2368 } 2205 }
2369 return 0; 2206 return 0;
2370 }; 2207 };
2371 } 2208 }
2372 }'''); 2209 }''');
2373 computeLibrarySourceErrors(source);
2374 assertErrors(source, [ 2210 assertErrors(source, [
2375 StaticWarningCode.MIXED_RETURN_TYPES, 2211 StaticWarningCode.MIXED_RETURN_TYPES,
2376 StaticWarningCode.MIXED_RETURN_TYPES 2212 StaticWarningCode.MIXED_RETURN_TYPES
2377 ]); 2213 ]);
2378 verify([source]); 2214 verify([source]);
2379 } 2215 }
2380 2216
2381 void test_mixedReturnTypes_method() { 2217 void test_mixedReturnTypes_method() {
2382 Source source = addSource(r''' 2218 Source source = addSource(r'''
2383 class C { 2219 class C {
2384 m(int x) { 2220 m(int x) {
2385 if (x < 0) { 2221 if (x < 0) {
2386 return; 2222 return;
2387 } 2223 }
2388 return 0; 2224 return 0;
2389 } 2225 }
2390 }'''); 2226 }''');
2391 computeLibrarySourceErrors(source);
2392 assertErrors(source, [ 2227 assertErrors(source, [
2393 StaticWarningCode.MIXED_RETURN_TYPES, 2228 StaticWarningCode.MIXED_RETURN_TYPES,
2394 StaticWarningCode.MIXED_RETURN_TYPES 2229 StaticWarningCode.MIXED_RETURN_TYPES
2395 ]); 2230 ]);
2396 verify([source]); 2231 verify([source]);
2397 } 2232 }
2398 2233
2399 void test_mixedReturnTypes_topLevelFunction() { 2234 void test_mixedReturnTypes_topLevelFunction() {
2400 Source source = addSource(r''' 2235 Source source = addSource(r'''
2401 f(int x) { 2236 f(int x) {
2402 if (x < 0) { 2237 if (x < 0) {
2403 return; 2238 return;
2404 } 2239 }
2405 return 0; 2240 return 0;
2406 }'''); 2241 }''');
2407 computeLibrarySourceErrors(source);
2408 assertErrors(source, [ 2242 assertErrors(source, [
2409 StaticWarningCode.MIXED_RETURN_TYPES, 2243 StaticWarningCode.MIXED_RETURN_TYPES,
2410 StaticWarningCode.MIXED_RETURN_TYPES 2244 StaticWarningCode.MIXED_RETURN_TYPES
2411 ]); 2245 ]);
2412 verify([source]); 2246 verify([source]);
2413 } 2247 }
2414 2248
2415 void test_newWithAbstractClass() { 2249 void test_newWithAbstractClass() {
2416 Source source = addSource(r''' 2250 Source source = addSource(r'''
2417 abstract class A {} 2251 abstract class A {}
2418 void f() { 2252 void f() {
2419 A a = new A(); 2253 A a = new A();
2420 }'''); 2254 }''');
2421 computeLibrarySourceErrors(source);
2422 assertErrors(source, [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]); 2255 assertErrors(source, [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]);
2423 verify([source]); 2256 verify([source]);
2424 } 2257 }
2425 2258
2426 void test_newWithInvalidTypeParameters() { 2259 void test_newWithInvalidTypeParameters() {
2427 Source source = addSource(r''' 2260 Source source = addSource(r'''
2428 class A {} 2261 class A {}
2429 f() { return new A<A>(); }'''); 2262 f() { return new A<A>(); }''');
2430 computeLibrarySourceErrors(source);
2431 assertErrors(source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]); 2263 assertErrors(source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]);
2432 verify([source]); 2264 verify([source]);
2433 } 2265 }
2434 2266
2435 void test_newWithInvalidTypeParameters_tooFew() { 2267 void test_newWithInvalidTypeParameters_tooFew() {
2436 Source source = addSource(r''' 2268 Source source = addSource(r'''
2437 class A {} 2269 class A {}
2438 class C<K, V> {} 2270 class C<K, V> {}
2439 f(p) { 2271 f(p) {
2440 return new C<A>(); 2272 return new C<A>();
2441 }'''); 2273 }''');
2442 computeLibrarySourceErrors(source);
2443 assertErrors(source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]); 2274 assertErrors(source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]);
2444 verify([source]); 2275 verify([source]);
2445 } 2276 }
2446 2277
2447 void test_newWithInvalidTypeParameters_tooMany() { 2278 void test_newWithInvalidTypeParameters_tooMany() {
2448 Source source = addSource(r''' 2279 Source source = addSource(r'''
2449 class A {} 2280 class A {}
2450 class C<E> {} 2281 class C<E> {}
2451 f(p) { 2282 f(p) {
2452 return new C<A, A>(); 2283 return new C<A, A>();
2453 }'''); 2284 }''');
2454 computeLibrarySourceErrors(source);
2455 assertErrors(source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]); 2285 assertErrors(source, [StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS]);
2456 verify([source]); 2286 verify([source]);
2457 } 2287 }
2458 2288
2459 void test_newWithNonType() { 2289 void test_newWithNonType() {
2460 Source source = addSource(r''' 2290 Source source = addSource(r'''
2461 var A = 0; 2291 var A = 0;
2462 void f() { 2292 void f() {
2463 var a = new A(); 2293 var a = new A();
2464 }'''); 2294 }''');
2465 computeLibrarySourceErrors(source);
2466 assertErrors(source, [StaticWarningCode.NEW_WITH_NON_TYPE]); 2295 assertErrors(source, [StaticWarningCode.NEW_WITH_NON_TYPE]);
2467 verify([source]); 2296 verify([source]);
2468 } 2297 }
2469 2298
2470 void test_newWithNonType_fromLibrary() { 2299 void test_newWithNonType_fromLibrary() {
2471 Source source1 = addNamedSource("/lib.dart", "class B {}"); 2300 Source source1 = addNamedSource("/lib.dart", "class B {}");
2472 Source source2 = addNamedSource( 2301 Source source2 = addNamedSource(
2473 "/lib2.dart", 2302 "/lib2.dart",
2474 r''' 2303 r'''
2475 import 'lib.dart' as lib; 2304 import 'lib.dart' as lib;
2476 void f() { 2305 void f() {
2477 var a = new lib.A(); 2306 var a = new lib.A();
2478 } 2307 }
2479 lib.B b;'''); 2308 lib.B b;''');
2480 computeLibrarySourceErrors(source1);
2481 computeLibrarySourceErrors(source2);
2482 assertErrors(source2, [StaticWarningCode.NEW_WITH_NON_TYPE]); 2309 assertErrors(source2, [StaticWarningCode.NEW_WITH_NON_TYPE]);
2483 verify([source1]); 2310 verify([source1]);
2484 } 2311 }
2485 2312
2486 void test_newWithUndefinedConstructor() { 2313 void test_newWithUndefinedConstructor() {
2487 Source source = addSource(r''' 2314 Source source = addSource(r'''
2488 class A { 2315 class A {
2489 A() {} 2316 A() {}
2490 } 2317 }
2491 f() { 2318 f() {
2492 new A.name(); 2319 new A.name();
2493 }'''); 2320 }''');
2494 computeLibrarySourceErrors(source);
2495 assertErrors(source, [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]); 2321 assertErrors(source, [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]);
2496 // no verify(), 'name' is not resolved 2322 // no verify(), 'name' is not resolved
2497 } 2323 }
2498 2324
2499 void test_newWithUndefinedConstructorDefault() { 2325 void test_newWithUndefinedConstructorDefault() {
2500 Source source = addSource(r''' 2326 Source source = addSource(r'''
2501 class A { 2327 class A {
2502 A.name() {} 2328 A.name() {}
2503 } 2329 }
2504 f() { 2330 f() {
2505 new A(); 2331 new A();
2506 }'''); 2332 }''');
2507 computeLibrarySourceErrors(source);
2508 assertErrors( 2333 assertErrors(
2509 source, [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]); 2334 source, [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]);
2510 verify([source]); 2335 verify([source]);
2511 } 2336 }
2512 2337
2513 void test_nonAbstractClassInheritsAbstractMemberFivePlus() { 2338 void test_nonAbstractClassInheritsAbstractMemberFivePlus() {
2514 Source source = addSource(r''' 2339 Source source = addSource(r'''
2515 abstract class A { 2340 abstract class A {
2516 m(); 2341 m();
2517 n(); 2342 n();
2518 o(); 2343 o();
2519 p(); 2344 p();
2520 q(); 2345 q();
2521 } 2346 }
2522 class C extends A { 2347 class C extends A {
2523 }'''); 2348 }''');
2524 computeLibrarySourceErrors(source);
2525 assertErrors(source, [ 2349 assertErrors(source, [
2526 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS 2350 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS
2527 ]); 2351 ]);
2528 verify([source]); 2352 verify([source]);
2529 } 2353 }
2530 2354
2531 void test_nonAbstractClassInheritsAbstractMemberFour() { 2355 void test_nonAbstractClassInheritsAbstractMemberFour() {
2532 Source source = addSource(r''' 2356 Source source = addSource(r'''
2533 abstract class A { 2357 abstract class A {
2534 m(); 2358 m();
2535 n(); 2359 n();
2536 o(); 2360 o();
2537 p(); 2361 p();
2538 } 2362 }
2539 class C extends A { 2363 class C extends A {
2540 }'''); 2364 }''');
2541 computeLibrarySourceErrors(source);
2542 assertErrors(source, 2365 assertErrors(source,
2543 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR]); 2366 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR]);
2544 verify([source]); 2367 verify([source]);
2545 } 2368 }
2546 2369
2547 void 2370 void
2548 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_interface() { 2371 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_interface() {
2549 // 15979 2372 // 15979
2550 Source source = addSource(r''' 2373 Source source = addSource(r'''
2551 abstract class M {} 2374 abstract class M {}
2552 abstract class A {} 2375 abstract class A {}
2553 abstract class I { 2376 abstract class I {
2554 m(); 2377 m();
2555 } 2378 }
2556 class B = A with M implements I;'''); 2379 class B = A with M implements I;''');
2557 computeLibrarySourceErrors(source);
2558 assertErrors(source, 2380 assertErrors(source,
2559 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2381 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2560 verify([source]); 2382 verify([source]);
2561 } 2383 }
2562 2384
2563 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_mixin() { 2385 void test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_mixin() {
2564 // 15979 2386 // 15979
2565 Source source = addSource(r''' 2387 Source source = addSource(r'''
2566 abstract class M { 2388 abstract class M {
2567 m(); 2389 m();
2568 } 2390 }
2569 abstract class A {} 2391 abstract class A {}
2570 class B = A with M;'''); 2392 class B = A with M;''');
2571 computeLibrarySourceErrors(source);
2572 assertErrors(source, 2393 assertErrors(source,
2573 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2394 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2574 verify([source]); 2395 verify([source]);
2575 } 2396 }
2576 2397
2577 void 2398 void
2578 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_superclass() { 2399 test_nonAbstractClassInheritsAbstractMemberOne_classTypeAlias_superclass() {
2579 // 15979 2400 // 15979
2580 Source source = addSource(r''' 2401 Source source = addSource(r'''
2581 class M {} 2402 class M {}
2582 abstract class A { 2403 abstract class A {
2583 m(); 2404 m();
2584 } 2405 }
2585 class B = A with M;'''); 2406 class B = A with M;''');
2586 computeLibrarySourceErrors(source);
2587 assertErrors(source, 2407 assertErrors(source,
2588 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2408 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2589 verify([source]); 2409 verify([source]);
2590 } 2410 }
2591 2411
2592 void 2412 void
2593 test_nonAbstractClassInheritsAbstractMemberOne_ensureCorrectFunctionSubtyp eIsUsedInImplementation() { 2413 test_nonAbstractClassInheritsAbstractMemberOne_ensureCorrectFunctionSubtyp eIsUsedInImplementation() {
2594 // 15028 2414 // 15028
2595 Source source = addSource(r''' 2415 Source source = addSource(r'''
2596 class C { 2416 class C {
2597 foo(int x) => x; 2417 foo(int x) => x;
2598 } 2418 }
2599 abstract class D { 2419 abstract class D {
2600 foo(x, [y]); 2420 foo(x, [y]);
2601 } 2421 }
2602 class E extends C implements D {}'''); 2422 class E extends C implements D {}''');
2603 computeLibrarySourceErrors(source);
2604 assertErrors(source, 2423 assertErrors(source,
2605 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2424 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2606 verify([source]); 2425 verify([source]);
2607 } 2426 }
2608 2427
2609 void test_nonAbstractClassInheritsAbstractMemberOne_getter_fromInterface() { 2428 void test_nonAbstractClassInheritsAbstractMemberOne_getter_fromInterface() {
2610 Source source = addSource(r''' 2429 Source source = addSource(r'''
2611 class I { 2430 class I {
2612 int get g {return 1;} 2431 int get g {return 1;}
2613 } 2432 }
2614 class C implements I { 2433 class C implements I {
2615 }'''); 2434 }''');
2616 computeLibrarySourceErrors(source);
2617 assertErrors(source, 2435 assertErrors(source,
2618 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2436 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2619 verify([source]); 2437 verify([source]);
2620 } 2438 }
2621 2439
2622 void test_nonAbstractClassInheritsAbstractMemberOne_getter_fromSuperclass() { 2440 void test_nonAbstractClassInheritsAbstractMemberOne_getter_fromSuperclass() {
2623 Source source = addSource(r''' 2441 Source source = addSource(r'''
2624 abstract class A { 2442 abstract class A {
2625 int get g; 2443 int get g;
2626 } 2444 }
2627 class C extends A { 2445 class C extends A {
2628 }'''); 2446 }''');
2629 computeLibrarySourceErrors(source);
2630 assertErrors(source, 2447 assertErrors(source,
2631 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2448 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2632 verify([source]); 2449 verify([source]);
2633 } 2450 }
2634 2451
2635 void test_nonAbstractClassInheritsAbstractMemberOne_method_fromInterface() { 2452 void test_nonAbstractClassInheritsAbstractMemberOne_method_fromInterface() {
2636 Source source = addSource(r''' 2453 Source source = addSource(r'''
2637 class I { 2454 class I {
2638 m(p) {} 2455 m(p) {}
2639 } 2456 }
2640 class C implements I { 2457 class C implements I {
2641 }'''); 2458 }''');
2642 computeLibrarySourceErrors(source);
2643 assertErrors(source, 2459 assertErrors(source,
2644 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2460 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2645 verify([source]); 2461 verify([source]);
2646 } 2462 }
2647 2463
2648 void test_nonAbstractClassInheritsAbstractMemberOne_method_fromSuperclass() { 2464 void test_nonAbstractClassInheritsAbstractMemberOne_method_fromSuperclass() {
2649 Source source = addSource(r''' 2465 Source source = addSource(r'''
2650 abstract class A { 2466 abstract class A {
2651 m(p); 2467 m(p);
2652 } 2468 }
2653 class C extends A { 2469 class C extends A {
2654 }'''); 2470 }''');
2655 computeLibrarySourceErrors(source);
2656 assertErrors(source, 2471 assertErrors(source,
2657 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2472 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2658 verify([source]); 2473 verify([source]);
2659 } 2474 }
2660 2475
2661 void 2476 void
2662 test_nonAbstractClassInheritsAbstractMemberOne_method_optionalParamCount() { 2477 test_nonAbstractClassInheritsAbstractMemberOne_method_optionalParamCount() {
2663 // 7640 2478 // 7640
2664 Source source = addSource(r''' 2479 Source source = addSource(r'''
2665 abstract class A { 2480 abstract class A {
2666 int x(int a); 2481 int x(int a);
2667 } 2482 }
2668 abstract class B { 2483 abstract class B {
2669 int x(int a, [int b]); 2484 int x(int a, [int b]);
2670 } 2485 }
2671 class C implements A, B { 2486 class C implements A, B {
2672 }'''); 2487 }''');
2673 computeLibrarySourceErrors(source);
2674 assertErrors(source, 2488 assertErrors(source,
2675 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2489 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2676 verify([source]); 2490 verify([source]);
2677 } 2491 }
2678 2492
2679 void test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_getter() { 2493 void test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_getter() {
2680 // 15001 2494 // 15001
2681 Source source = addSource(r''' 2495 Source source = addSource(r'''
2682 abstract class A { get g1; get g2; } 2496 abstract class A { get g1; get g2; }
2683 abstract class B implements A { get g1 => 1; } 2497 abstract class B implements A { get g1 => 1; }
2684 class C extends Object with B {}'''); 2498 class C extends Object with B {}''');
2685 computeLibrarySourceErrors(source);
2686 assertErrors(source, 2499 assertErrors(source,
2687 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2500 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2688 } 2501 }
2689 2502
2690 void test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_method() { 2503 void test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_method() {
2691 // 15001 2504 // 15001
2692 Source source = addSource(r''' 2505 Source source = addSource(r'''
2693 abstract class A { m1(); m2(); } 2506 abstract class A { m1(); m2(); }
2694 abstract class B implements A { m1() => 1; } 2507 abstract class B implements A { m1() => 1; }
2695 class C extends Object with B {}'''); 2508 class C extends Object with B {}''');
2696 computeLibrarySourceErrors(source);
2697 assertErrors(source, 2509 assertErrors(source,
2698 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2510 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2699 } 2511 }
2700 2512
2701 void test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_setter() { 2513 void test_nonAbstractClassInheritsAbstractMemberOne_mixinInherits_setter() {
2702 // 15001 2514 // 15001
2703 Source source = addSource(r''' 2515 Source source = addSource(r'''
2704 abstract class A { set s1(v); set s2(v); } 2516 abstract class A { set s1(v); set s2(v); }
2705 abstract class B implements A { set s1(v) {} } 2517 abstract class B implements A { set s1(v) {} }
2706 class C extends Object with B {}'''); 2518 class C extends Object with B {}''');
2707 computeLibrarySourceErrors(source);
2708 assertErrors(source, 2519 assertErrors(source,
2709 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2520 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2710 } 2521 }
2711 2522
2712 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_interface() { 2523 void test_nonAbstractClassInheritsAbstractMemberOne_noSuchMethod_interface() {
2713 // 15979 2524 // 15979
2714 Source source = addSource(r''' 2525 Source source = addSource(r'''
2715 class I { 2526 class I {
2716 noSuchMethod(v) => ''; 2527 noSuchMethod(v) => '';
2717 } 2528 }
2718 abstract class A { 2529 abstract class A {
2719 m(); 2530 m();
2720 } 2531 }
2721 class B extends A implements I { 2532 class B extends A implements I {
2722 }'''); 2533 }''');
2723 computeLibrarySourceErrors(source);
2724 assertErrors(source, 2534 assertErrors(source,
2725 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2535 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2726 verify([source]); 2536 verify([source]);
2727 } 2537 }
2728 2538
2729 void 2539 void
2730 test_nonAbstractClassInheritsAbstractMemberOne_setter_and_implicitSetter() { 2540 test_nonAbstractClassInheritsAbstractMemberOne_setter_and_implicitSetter() {
2731 // test from language/override_inheritance_abstract_test_14.dart 2541 // test from language/override_inheritance_abstract_test_14.dart
2732 Source source = addSource(r''' 2542 Source source = addSource(r'''
2733 abstract class A { 2543 abstract class A {
2734 set field(_); 2544 set field(_);
2735 } 2545 }
2736 abstract class I { 2546 abstract class I {
2737 var field; 2547 var field;
2738 } 2548 }
2739 class B extends A implements I { 2549 class B extends A implements I {
2740 get field => 0; 2550 get field => 0;
2741 }'''); 2551 }''');
2742 computeLibrarySourceErrors(source);
2743 assertErrors(source, 2552 assertErrors(source,
2744 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2553 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2745 verify([source]); 2554 verify([source]);
2746 } 2555 }
2747 2556
2748 void test_nonAbstractClassInheritsAbstractMemberOne_setter_fromInterface() { 2557 void test_nonAbstractClassInheritsAbstractMemberOne_setter_fromInterface() {
2749 Source source = addSource(r''' 2558 Source source = addSource(r'''
2750 class I { 2559 class I {
2751 set s(int i) {} 2560 set s(int i) {}
2752 } 2561 }
2753 class C implements I { 2562 class C implements I {
2754 }'''); 2563 }''');
2755 computeLibrarySourceErrors(source);
2756 assertErrors(source, 2564 assertErrors(source,
2757 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2565 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2758 verify([source]); 2566 verify([source]);
2759 } 2567 }
2760 2568
2761 void test_nonAbstractClassInheritsAbstractMemberOne_setter_fromSuperclass() { 2569 void test_nonAbstractClassInheritsAbstractMemberOne_setter_fromSuperclass() {
2762 Source source = addSource(r''' 2570 Source source = addSource(r'''
2763 abstract class A { 2571 abstract class A {
2764 set s(int i); 2572 set s(int i);
2765 } 2573 }
2766 class C extends A { 2574 class C extends A {
2767 }'''); 2575 }''');
2768 computeLibrarySourceErrors(source);
2769 assertErrors(source, 2576 assertErrors(source,
2770 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2577 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2771 verify([source]); 2578 verify([source]);
2772 } 2579 }
2773 2580
2774 void test_nonAbstractClassInheritsAbstractMemberOne_superclasses_interface() { 2581 void test_nonAbstractClassInheritsAbstractMemberOne_superclasses_interface() {
2775 // bug 11154 2582 // bug 11154
2776 Source source = addSource(r''' 2583 Source source = addSource(r'''
2777 class A { 2584 class A {
2778 get a => 'a'; 2585 get a => 'a';
2779 } 2586 }
2780 abstract class B implements A { 2587 abstract class B implements A {
2781 get b => 'b'; 2588 get b => 'b';
2782 } 2589 }
2783 class C extends B { 2590 class C extends B {
2784 }'''); 2591 }''');
2785 computeLibrarySourceErrors(source);
2786 assertErrors(source, 2592 assertErrors(source,
2787 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2593 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2788 verify([source]); 2594 verify([source]);
2789 } 2595 }
2790 2596
2791 void 2597 void
2792 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_miss ingGetter() { 2598 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_miss ingGetter() {
2793 // 16133 2599 // 16133
2794 Source source = addSource(r''' 2600 Source source = addSource(r'''
2795 class I { 2601 class I {
2796 var v; 2602 var v;
2797 } 2603 }
2798 class C implements I { 2604 class C implements I {
2799 set v(_) {} 2605 set v(_) {}
2800 }'''); 2606 }''');
2801 computeLibrarySourceErrors(source);
2802 assertErrors(source, 2607 assertErrors(source,
2803 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2608 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2804 verify([source]); 2609 verify([source]);
2805 } 2610 }
2806 2611
2807 void 2612 void
2808 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_miss ingSetter() { 2613 test_nonAbstractClassInheritsAbstractMemberOne_variable_fromInterface_miss ingSetter() {
2809 // 16133 2614 // 16133
2810 Source source = addSource(r''' 2615 Source source = addSource(r'''
2811 class I { 2616 class I {
2812 var v; 2617 var v;
2813 } 2618 }
2814 class C implements I { 2619 class C implements I {
2815 get v => 1; 2620 get v => 1;
2816 }'''); 2621 }''');
2817 computeLibrarySourceErrors(source);
2818 assertErrors(source, 2622 assertErrors(source,
2819 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]); 2623 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE]);
2820 verify([source]); 2624 verify([source]);
2821 } 2625 }
2822 2626
2823 void test_nonAbstractClassInheritsAbstractMemberThree() { 2627 void test_nonAbstractClassInheritsAbstractMemberThree() {
2824 Source source = addSource(r''' 2628 Source source = addSource(r'''
2825 abstract class A { 2629 abstract class A {
2826 m(); 2630 m();
2827 n(); 2631 n();
2828 o(); 2632 o();
2829 } 2633 }
2830 class C extends A { 2634 class C extends A {
2831 }'''); 2635 }''');
2832 computeLibrarySourceErrors(source);
2833 assertErrors(source, 2636 assertErrors(source,
2834 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE]); 2637 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE]);
2835 verify([source]); 2638 verify([source]);
2836 } 2639 }
2837 2640
2838 void test_nonAbstractClassInheritsAbstractMemberTwo() { 2641 void test_nonAbstractClassInheritsAbstractMemberTwo() {
2839 Source source = addSource(r''' 2642 Source source = addSource(r'''
2840 abstract class A { 2643 abstract class A {
2841 m(); 2644 m();
2842 n(); 2645 n();
2843 } 2646 }
2844 class C extends A { 2647 class C extends A {
2845 }'''); 2648 }''');
2846 computeLibrarySourceErrors(source);
2847 assertErrors(source, 2649 assertErrors(source,
2848 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); 2650 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]);
2849 verify([source]); 2651 verify([source]);
2850 } 2652 }
2851 2653
2852 void 2654 void
2853 test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromInterface_miss ingBoth() { 2655 test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromInterface_miss ingBoth() {
2854 // 16133 2656 // 16133
2855 Source source = addSource(r''' 2657 Source source = addSource(r'''
2856 class I { 2658 class I {
2857 var v; 2659 var v;
2858 } 2660 }
2859 class C implements I { 2661 class C implements I {
2860 }'''); 2662 }''');
2861 computeLibrarySourceErrors(source);
2862 assertErrors(source, 2663 assertErrors(source,
2863 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); 2664 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]);
2864 verify([source]); 2665 verify([source]);
2865 } 2666 }
2866 2667
2867 void 2668 void
2868 test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromMixin_missingB oth() { 2669 test_nonAbstractClassInheritsAbstractMemberTwo_variable_fromMixin_missingB oth() {
2869 // 26411 2670 // 26411
2870 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); 2671 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
2871 Source source = addSource(r''' 2672 Source source = addSource(r'''
2872 class A { 2673 class A {
2873 int f; 2674 int f;
2874 } 2675 }
2875 class B extends A {} 2676 class B extends A {}
2876 class C extends Object with B {} 2677 class C extends Object with B {}
2877 '''); 2678 ''');
2878 computeLibrarySourceErrors(source);
2879 assertErrors(source, 2679 assertErrors(source,
2880 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]); 2680 [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO]);
2881 verify([source]); 2681 verify([source]);
2882 } 2682 }
2883 2683
2884 void test_nonTypeInCatchClause_noElement() { 2684 void test_nonTypeInCatchClause_noElement() {
2885 Source source = addSource(r''' 2685 Source source = addSource(r'''
2886 f() { 2686 f() {
2887 try { 2687 try {
2888 } on T catch (e) { 2688 } on T catch (e) {
2889 } 2689 }
2890 }'''); 2690 }''');
2891 computeLibrarySourceErrors(source);
2892 assertErrors(source, [StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE]); 2691 assertErrors(source, [StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE]);
2893 verify([source]); 2692 verify([source]);
2894 } 2693 }
2895 2694
2896 void test_nonTypeInCatchClause_notType() { 2695 void test_nonTypeInCatchClause_notType() {
2897 Source source = addSource(r''' 2696 Source source = addSource(r'''
2898 var T = 0; 2697 var T = 0;
2899 f() { 2698 f() {
2900 try { 2699 try {
2901 } on T catch (e) { 2700 } on T catch (e) {
2902 } 2701 }
2903 }'''); 2702 }''');
2904 computeLibrarySourceErrors(source);
2905 assertErrors(source, [StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE]); 2703 assertErrors(source, [StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE]);
2906 verify([source]); 2704 verify([source]);
2907 } 2705 }
2908 2706
2909 void test_nonVoidReturnForOperator() { 2707 void test_nonVoidReturnForOperator() {
2910 Source source = addSource(r''' 2708 Source source = addSource(r'''
2911 class A { 2709 class A {
2912 int operator []=(a, b) { return a; } 2710 int operator []=(a, b) { return a; }
2913 }'''); 2711 }''');
2914 computeLibrarySourceErrors(source);
2915 assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]); 2712 assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]);
2916 verify([source]); 2713 verify([source]);
2917 } 2714 }
2918 2715
2919 void test_nonVoidReturnForSetter_function() { 2716 void test_nonVoidReturnForSetter_function() {
2920 Source source = addSource(r''' 2717 Source source = addSource(r'''
2921 int set x(int v) { 2718 int set x(int v) {
2922 return 42; 2719 return 42;
2923 }'''); 2720 }''');
2924 computeLibrarySourceErrors(source);
2925 assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]); 2721 assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]);
2926 verify([source]); 2722 verify([source]);
2927 } 2723 }
2928 2724
2929 void test_nonVoidReturnForSetter_method() { 2725 void test_nonVoidReturnForSetter_method() {
2930 Source source = addSource(r''' 2726 Source source = addSource(r'''
2931 class A { 2727 class A {
2932 int set x(int v) { 2728 int set x(int v) {
2933 return 42; 2729 return 42;
2934 } 2730 }
2935 }'''); 2731 }''');
2936 computeLibrarySourceErrors(source);
2937 assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]); 2732 assertErrors(source, [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]);
2938 verify([source]); 2733 verify([source]);
2939 } 2734 }
2940 2735
2941 void test_notAType() { 2736 void test_notAType() {
2942 Source source = addSource(r''' 2737 Source source = addSource(r'''
2943 f() {} 2738 f() {}
2944 main() { 2739 main() {
2945 f v = null; 2740 f v = null;
2946 }'''); 2741 }''');
2947 computeLibrarySourceErrors(source);
2948 assertErrors(source, [StaticWarningCode.NOT_A_TYPE]); 2742 assertErrors(source, [StaticWarningCode.NOT_A_TYPE]);
2949 verify([source]); 2743 verify([source]);
2950 } 2744 }
2951 2745
2952 void test_notEnoughRequiredArguments() { 2746 void test_notEnoughRequiredArguments() {
2953 Source source = addSource(r''' 2747 Source source = addSource(r'''
2954 f(int a, String b) {} 2748 f(int a, String b) {}
2955 main() { 2749 main() {
2956 f(); 2750 f();
2957 }'''); 2751 }''');
2958 computeLibrarySourceErrors(source);
2959 assertErrors(source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); 2752 assertErrors(source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]);
2960 verify([source]); 2753 verify([source]);
2961 } 2754 }
2962 2755
2963 void test_notEnoughRequiredArguments_functionExpression() { 2756 void test_notEnoughRequiredArguments_functionExpression() {
2964 Source source = addSource(r''' 2757 Source source = addSource(r'''
2965 main() { 2758 main() {
2966 (int x) {} (); 2759 (int x) {} ();
2967 }'''); 2760 }''');
2968 computeLibrarySourceErrors(source);
2969 assertErrors(source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); 2761 assertErrors(source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]);
2970 verify([source]); 2762 verify([source]);
2971 } 2763 }
2972 2764
2973 void test_notEnoughRequiredArguments_getterReturningFunction() { 2765 void test_notEnoughRequiredArguments_getterReturningFunction() {
2974 Source source = addSource(r''' 2766 Source source = addSource(r'''
2975 typedef Getter(self); 2767 typedef Getter(self);
2976 Getter getter = (x) => x; 2768 Getter getter = (x) => x;
2977 main() { 2769 main() {
2978 getter(); 2770 getter();
2979 }'''); 2771 }''');
2980 computeLibrarySourceErrors(source);
2981 assertErrors(source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); 2772 assertErrors(source, [StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]);
2982 verify([source]); 2773 verify([source]);
2983 } 2774 }
2984 2775
2985 void test_partOfDifferentLibrary() { 2776 void test_partOfDifferentLibrary() {
2986 Source source = addSource(r''' 2777 Source source = addSource(r'''
2987 library lib; 2778 library lib;
2988 part 'part.dart';'''); 2779 part 'part.dart';''');
2989 addNamedSource("/part.dart", "part of lub;"); 2780 addNamedSource("/part.dart", "part of lub;");
2990 computeLibrarySourceErrors(source);
2991 assertErrors(source, [StaticWarningCode.PART_OF_DIFFERENT_LIBRARY]); 2781 assertErrors(source, [StaticWarningCode.PART_OF_DIFFERENT_LIBRARY]);
2992 verify([source]); 2782 verify([source]);
2993 } 2783 }
2994 2784
2995 void test_redirectToInvalidFunctionType() { 2785 void test_redirectToInvalidFunctionType() {
2996 Source source = addSource(r''' 2786 Source source = addSource(r'''
2997 class A implements B { 2787 class A implements B {
2998 A(int p) {} 2788 A(int p) {}
2999 } 2789 }
3000 class B { 2790 class B {
3001 factory B() = A; 2791 factory B() = A;
3002 }'''); 2792 }''');
3003 computeLibrarySourceErrors(source);
3004 assertErrors(source, [StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE]); 2793 assertErrors(source, [StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE]);
3005 verify([source]); 2794 verify([source]);
3006 } 2795 }
3007 2796
3008 void test_redirectToInvalidReturnType() { 2797 void test_redirectToInvalidReturnType() {
3009 Source source = addSource(r''' 2798 Source source = addSource(r'''
3010 class A { 2799 class A {
3011 A() {} 2800 A() {}
3012 } 2801 }
3013 class B { 2802 class B {
3014 factory B() = A; 2803 factory B() = A;
3015 }'''); 2804 }''');
3016 computeLibrarySourceErrors(source);
3017 assertErrors(source, [StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE]); 2805 assertErrors(source, [StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE]);
3018 verify([source]); 2806 verify([source]);
3019 } 2807 }
3020 2808
3021 void test_redirectToMissingConstructor_named() { 2809 void test_redirectToMissingConstructor_named() {
3022 Source source = addSource(r''' 2810 Source source = addSource(r'''
3023 class A implements B{ 2811 class A implements B{
3024 A() {} 2812 A() {}
3025 } 2813 }
3026 class B { 2814 class B {
3027 factory B() = A.name; 2815 factory B() = A.name;
3028 }'''); 2816 }''');
3029 computeLibrarySourceErrors(source);
3030 assertErrors(source, [StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); 2817 assertErrors(source, [StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR]);
3031 } 2818 }
3032 2819
3033 void test_redirectToMissingConstructor_unnamed() { 2820 void test_redirectToMissingConstructor_unnamed() {
3034 Source source = addSource(r''' 2821 Source source = addSource(r'''
3035 class A implements B{ 2822 class A implements B{
3036 A.name() {} 2823 A.name() {}
3037 } 2824 }
3038 class B { 2825 class B {
3039 factory B() = A; 2826 factory B() = A;
3040 }'''); 2827 }''');
3041 computeLibrarySourceErrors(source);
3042 assertErrors(source, [StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); 2828 assertErrors(source, [StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR]);
3043 } 2829 }
3044 2830
3045 void test_redirectToNonClass_notAType() { 2831 void test_redirectToNonClass_notAType() {
3046 Source source = addSource(r''' 2832 Source source = addSource(r'''
3047 class B { 2833 class B {
3048 int A; 2834 int A;
3049 factory B() = A; 2835 factory B() = A;
3050 }'''); 2836 }''');
3051 computeLibrarySourceErrors(source);
3052 assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]); 2837 assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]);
3053 verify([source]); 2838 verify([source]);
3054 } 2839 }
3055 2840
3056 void test_redirectToNonClass_undefinedIdentifier() { 2841 void test_redirectToNonClass_undefinedIdentifier() {
3057 Source source = addSource(r''' 2842 Source source = addSource(r'''
3058 class B { 2843 class B {
3059 factory B() = A; 2844 factory B() = A;
3060 }'''); 2845 }''');
3061 computeLibrarySourceErrors(source);
3062 assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]); 2846 assertErrors(source, [StaticWarningCode.REDIRECT_TO_NON_CLASS]);
3063 verify([source]); 2847 verify([source]);
3064 } 2848 }
3065 2849
3066 void test_returnWithoutValue_async() { 2850 void test_returnWithoutValue_async() {
3067 Source source = addSource(''' 2851 Source source = addSource('''
3068 import 'dart:async'; 2852 import 'dart:async';
3069 Future<int> f() async { 2853 Future<int> f() async {
3070 return; 2854 return;
3071 } 2855 }
3072 '''); 2856 ''');
3073 computeLibrarySourceErrors(source);
3074 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); 2857 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]);
3075 verify([source]); 2858 verify([source]);
3076 } 2859 }
3077 2860
3078 void test_returnWithoutValue_factoryConstructor() { 2861 void test_returnWithoutValue_factoryConstructor() {
3079 Source source = addSource("class A { factory A() { return; } }"); 2862 Source source = addSource("class A { factory A() { return; } }");
3080 computeLibrarySourceErrors(source);
3081 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); 2863 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]);
3082 verify([source]); 2864 verify([source]);
3083 } 2865 }
3084 2866
3085 void test_returnWithoutValue_function() { 2867 void test_returnWithoutValue_function() {
3086 Source source = addSource("int f() { return; }"); 2868 Source source = addSource("int f() { return; }");
3087 computeLibrarySourceErrors(source);
3088 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); 2869 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]);
3089 verify([source]); 2870 verify([source]);
3090 } 2871 }
3091 2872
3092 void test_returnWithoutValue_method() { 2873 void test_returnWithoutValue_method() {
3093 Source source = addSource("class A { int m() { return; } }"); 2874 Source source = addSource("class A { int m() { return; } }");
3094 computeLibrarySourceErrors(source);
3095 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); 2875 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]);
3096 verify([source]); 2876 verify([source]);
3097 } 2877 }
3098 2878
3099 void test_returnWithoutValue_mixedReturnTypes_function() { 2879 void test_returnWithoutValue_mixedReturnTypes_function() {
3100 // Tests that only the RETURN_WITHOUT_VALUE warning is created, and no 2880 // Tests that only the RETURN_WITHOUT_VALUE warning is created, and no
3101 // MIXED_RETURN_TYPES are created. 2881 // MIXED_RETURN_TYPES are created.
3102 Source source = addSource(r''' 2882 Source source = addSource(r'''
3103 int f(int x) { 2883 int f(int x) {
3104 if (x < 0) { 2884 if (x < 0) {
3105 return 1; 2885 return 1;
3106 } 2886 }
3107 return; 2887 return;
3108 }'''); 2888 }''');
3109 computeLibrarySourceErrors(source);
3110 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]); 2889 assertErrors(source, [StaticWarningCode.RETURN_WITHOUT_VALUE]);
3111 verify([source]); 2890 verify([source]);
3112 } 2891 }
3113 2892
3114 void test_staticAccessToInstanceMember_method_invocation() { 2893 void test_staticAccessToInstanceMember_method_invocation() {
3115 Source source = addSource(r''' 2894 Source source = addSource(r'''
3116 class A { 2895 class A {
3117 m() {} 2896 m() {}
3118 } 2897 }
3119 main() { 2898 main() {
3120 A.m(); 2899 A.m();
3121 }'''); 2900 }''');
3122 computeLibrarySourceErrors(source);
3123 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); 2901 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]);
3124 verify([source]); 2902 verify([source]);
3125 } 2903 }
3126 2904
3127 void test_staticAccessToInstanceMember_method_reference() { 2905 void test_staticAccessToInstanceMember_method_reference() {
3128 Source source = addSource(r''' 2906 Source source = addSource(r'''
3129 class A { 2907 class A {
3130 m() {} 2908 m() {}
3131 } 2909 }
3132 main() { 2910 main() {
3133 A.m; 2911 A.m;
3134 }'''); 2912 }''');
3135 computeLibrarySourceErrors(source);
3136 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); 2913 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]);
3137 verify([source]); 2914 verify([source]);
3138 } 2915 }
3139 2916
3140 void test_staticAccessToInstanceMember_propertyAccess_field() { 2917 void test_staticAccessToInstanceMember_propertyAccess_field() {
3141 Source source = addSource(r''' 2918 Source source = addSource(r'''
3142 class A { 2919 class A {
3143 var f; 2920 var f;
3144 } 2921 }
3145 main() { 2922 main() {
3146 A.f; 2923 A.f;
3147 }'''); 2924 }''');
3148 computeLibrarySourceErrors(source);
3149 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); 2925 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]);
3150 verify([source]); 2926 verify([source]);
3151 } 2927 }
3152 2928
3153 void test_staticAccessToInstanceMember_propertyAccess_getter() { 2929 void test_staticAccessToInstanceMember_propertyAccess_getter() {
3154 Source source = addSource(r''' 2930 Source source = addSource(r'''
3155 class A { 2931 class A {
3156 get f => 42; 2932 get f => 42;
3157 } 2933 }
3158 main() { 2934 main() {
3159 A.f; 2935 A.f;
3160 }'''); 2936 }''');
3161 computeLibrarySourceErrors(source);
3162 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); 2937 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]);
3163 verify([source]); 2938 verify([source]);
3164 } 2939 }
3165 2940
3166 void test_staticAccessToInstanceMember_propertyAccess_setter() { 2941 void test_staticAccessToInstanceMember_propertyAccess_setter() {
3167 Source source = addSource(r''' 2942 Source source = addSource(r'''
3168 class A { 2943 class A {
3169 set f(x) {} 2944 set f(x) {}
3170 } 2945 }
3171 main() { 2946 main() {
3172 A.f = 42; 2947 A.f = 42;
3173 }'''); 2948 }''');
3174 computeLibrarySourceErrors(source);
3175 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]); 2949 assertErrors(source, [StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMBER]);
3176 verify([source]); 2950 verify([source]);
3177 } 2951 }
3178 2952
3179 void test_switchExpressionNotAssignable() { 2953 void test_switchExpressionNotAssignable() {
3180 Source source = addSource(r''' 2954 Source source = addSource(r'''
3181 f(int p) { 2955 f(int p) {
3182 switch (p) { 2956 switch (p) {
3183 case 'a': break; 2957 case 'a': break;
3184 } 2958 }
3185 }'''); 2959 }''');
3186 computeLibrarySourceErrors(source);
3187 assertErrors(source, [StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE]); 2960 assertErrors(source, [StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE]);
3188 verify([source]); 2961 verify([source]);
3189 } 2962 }
3190 2963
3191 void test_typeAnnotationDeferredClass_asExpression() { 2964 void test_typeAnnotationDeferredClass_asExpression() {
3192 resolveWithErrors(<String>[ 2965 resolveWithErrors(<String>[
3193 r''' 2966 r'''
3194 library lib1; 2967 library lib1;
3195 class A {}''', 2968 class A {}''',
3196 r''' 2969 r'''
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
3375 3148
3376 void test_typeAnnotationGenericFunctionParameter_localFunction() { 3149 void test_typeAnnotationGenericFunctionParameter_localFunction() {
3377 Source source = addSource(r''' 3150 Source source = addSource(r'''
3378 class A { 3151 class A {
3379 void method() { 3152 void method() {
3380 T local<T>(Object t) { 3153 T local<T>(Object t) {
3381 return (t is T) ? t : null; 3154 return (t is T) ? t : null;
3382 } 3155 }
3383 } 3156 }
3384 }'''); 3157 }''');
3385 computeLibrarySourceErrors(source);
3386 assertErrors( 3158 assertErrors(
3387 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]); 3159 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]);
3388 verify([source]); 3160 verify([source]);
3389 } 3161 }
3390 3162
3391 void test_typeAnnotationGenericFunctionParameter_method() { 3163 void test_typeAnnotationGenericFunctionParameter_method() {
3392 Source source = addSource(r''' 3164 Source source = addSource(r'''
3393 class A { 3165 class A {
3394 T method<T>(Object t) { 3166 T method<T>(Object t) {
3395 return (t is T) ? t : null; 3167 return (t is T) ? t : null;
3396 } 3168 }
3397 }'''); 3169 }''');
3398 computeLibrarySourceErrors(source);
3399 assertErrors( 3170 assertErrors(
3400 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]); 3171 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]);
3401 verify([source]); 3172 verify([source]);
3402 } 3173 }
3403 3174
3404 void test_typeAnnotationGenericFunctionParameter_topLevelFunction() { 3175 void test_typeAnnotationGenericFunctionParameter_topLevelFunction() {
3405 Source source = addSource(r''' 3176 Source source = addSource(r'''
3406 T function<T>(Object t) { 3177 T function<T>(Object t) {
3407 return (t is T) ? t : null; 3178 return (t is T) ? t : null;
3408 }'''); 3179 }''');
3409 computeLibrarySourceErrors(source);
3410 assertErrors( 3180 assertErrors(
3411 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]); 3181 source, [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]);
3412 verify([source]); 3182 verify([source]);
3413 } 3183 }
3414 3184
3415 void test_typeParameterReferencedByStatic_field() { 3185 void test_typeParameterReferencedByStatic_field() {
3416 Source source = addSource(r''' 3186 Source source = addSource(r'''
3417 class A<K> { 3187 class A<K> {
3418 static K k; 3188 static K k;
3419 }'''); 3189 }''');
3420 computeLibrarySourceErrors(source);
3421 assertErrors( 3190 assertErrors(
3422 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); 3191 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
3423 verify([source]); 3192 verify([source]);
3424 } 3193 }
3425 3194
3426 void test_typeParameterReferencedByStatic_getter() { 3195 void test_typeParameterReferencedByStatic_getter() {
3427 Source source = addSource(r''' 3196 Source source = addSource(r'''
3428 class A<K> { 3197 class A<K> {
3429 static K get k => null; 3198 static K get k => null;
3430 }'''); 3199 }''');
3431 computeLibrarySourceErrors(source);
3432 assertErrors( 3200 assertErrors(
3433 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); 3201 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
3434 verify([source]); 3202 verify([source]);
3435 } 3203 }
3436 3204
3437 void test_typeParameterReferencedByStatic_methodBodyReference() { 3205 void test_typeParameterReferencedByStatic_methodBodyReference() {
3438 Source source = addSource(r''' 3206 Source source = addSource(r'''
3439 class A<K> { 3207 class A<K> {
3440 static m() { 3208 static m() {
3441 K k; 3209 K k;
3442 } 3210 }
3443 }'''); 3211 }''');
3444 computeLibrarySourceErrors(source);
3445 assertErrors( 3212 assertErrors(
3446 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); 3213 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
3447 verify([source]); 3214 verify([source]);
3448 } 3215 }
3449 3216
3450 void test_typeParameterReferencedByStatic_methodParameter() { 3217 void test_typeParameterReferencedByStatic_methodParameter() {
3451 Source source = addSource(r''' 3218 Source source = addSource(r'''
3452 class A<K> { 3219 class A<K> {
3453 static m(K k) {} 3220 static m(K k) {}
3454 }'''); 3221 }''');
3455 computeLibrarySourceErrors(source);
3456 assertErrors( 3222 assertErrors(
3457 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); 3223 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
3458 verify([source]); 3224 verify([source]);
3459 } 3225 }
3460 3226
3461 void test_typeParameterReferencedByStatic_methodReturn() { 3227 void test_typeParameterReferencedByStatic_methodReturn() {
3462 Source source = addSource(r''' 3228 Source source = addSource(r'''
3463 class A<K> { 3229 class A<K> {
3464 static K m() { return null; } 3230 static K m() { return null; }
3465 }'''); 3231 }''');
3466 computeLibrarySourceErrors(source);
3467 assertErrors( 3232 assertErrors(
3468 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); 3233 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
3469 verify([source]); 3234 verify([source]);
3470 } 3235 }
3471 3236
3472 void test_typeParameterReferencedByStatic_setter() { 3237 void test_typeParameterReferencedByStatic_setter() {
3473 Source source = addSource(r''' 3238 Source source = addSource(r'''
3474 class A<K> { 3239 class A<K> {
3475 static set s(K k) {} 3240 static set s(K k) {}
3476 }'''); 3241 }''');
3477 computeLibrarySourceErrors(source);
3478 assertErrors( 3242 assertErrors(
3479 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); 3243 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
3480 verify([source]); 3244 verify([source]);
3481 } 3245 }
3482 3246
3483 void test_typePromotion_functionType_arg_InterToDyn() { 3247 void test_typePromotion_functionType_arg_InterToDyn() {
3484 Source source = addSource(r''' 3248 Source source = addSource(r'''
3485 typedef FuncDyn(x); 3249 typedef FuncDyn(x);
3486 typedef FuncA(A a); 3250 typedef FuncA(A a);
3487 class A {} 3251 class A {}
3488 class B {} 3252 class B {}
3489 main(FuncA f) { 3253 main(FuncA f) {
3490 if (f is FuncDyn) { 3254 if (f is FuncDyn) {
3491 f(new B()); 3255 f(new B());
3492 } 3256 }
3493 }'''); 3257 }''');
3494 computeLibrarySourceErrors(source);
3495 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 3258 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
3496 } 3259 }
3497 3260
3498 void test_typeTestNonType() { 3261 void test_typeTestNonType() {
3499 Source source = addSource(r''' 3262 Source source = addSource(r'''
3500 var A = 0; 3263 var A = 0;
3501 f(var p) { 3264 f(var p) {
3502 if (p is A) { 3265 if (p is A) {
3503 } 3266 }
3504 }'''); 3267 }''');
3505 computeLibrarySourceErrors(source);
3506 assertErrors(source, [StaticWarningCode.TYPE_TEST_WITH_NON_TYPE]); 3268 assertErrors(source, [StaticWarningCode.TYPE_TEST_WITH_NON_TYPE]);
3507 verify([source]); 3269 verify([source]);
3508 } 3270 }
3509 3271
3510 void test_typeTestWithUndefinedName() { 3272 void test_typeTestWithUndefinedName() {
3511 Source source = addSource(r''' 3273 Source source = addSource(r'''
3512 f(var p) { 3274 f(var p) {
3513 if (p is A) { 3275 if (p is A) {
3514 } 3276 }
3515 }'''); 3277 }''');
3516 computeLibrarySourceErrors(source);
3517 assertErrors(source, [StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME]); 3278 assertErrors(source, [StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME]);
3518 verify([source]); 3279 verify([source]);
3519 } 3280 }
3520 3281
3521 void test_undefinedClass_instanceCreation() { 3282 void test_undefinedClass_instanceCreation() {
3522 Source source = addSource("f() { new C(); }"); 3283 Source source = addSource("f() { new C(); }");
3523 computeLibrarySourceErrors(source);
3524 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); 3284 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]);
3525 } 3285 }
3526 3286
3527 void test_undefinedClass_variableDeclaration() { 3287 void test_undefinedClass_variableDeclaration() {
3528 Source source = addSource("f() { C c; }"); 3288 Source source = addSource("f() { C c; }");
3529 computeLibrarySourceErrors(source);
3530 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); 3289 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]);
3531 } 3290 }
3532 3291
3533 void test_undefinedClassBoolean_variableDeclaration() { 3292 void test_undefinedClassBoolean_variableDeclaration() {
3534 Source source = addSource("f() { boolean v; }"); 3293 Source source = addSource("f() { boolean v; }");
3535 computeLibrarySourceErrors(source);
3536 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS_BOOLEAN]); 3294 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS_BOOLEAN]);
3537 } 3295 }
3538 3296
3539 void test_undefinedGetter_fromLibrary() { 3297 void test_undefinedGetter_fromLibrary() {
3540 Source source1 = addNamedSource("/lib.dart", ""); 3298 Source source1 = addNamedSource("/lib.dart", "");
3541 Source source2 = addNamedSource( 3299 Source source2 = addNamedSource(
3542 "/lib2.dart", 3300 "/lib2.dart",
3543 r''' 3301 r'''
3544 import 'lib.dart' as lib; 3302 import 'lib.dart' as lib;
3545 void f() { 3303 void f() {
3546 var g = lib.gg; 3304 var g = lib.gg;
3547 }'''); 3305 }''');
3548 computeLibrarySourceErrors(source1);
3549 computeLibrarySourceErrors(source2);
3550 assertErrors(source2, [StaticWarningCode.UNDEFINED_GETTER]); 3306 assertErrors(source2, [StaticWarningCode.UNDEFINED_GETTER]);
3551 verify([source1]); 3307 verify([source1]);
3552 } 3308 }
3553 3309
3554 void test_undefinedIdentifier_for() { 3310 void test_undefinedIdentifier_for() {
3555 Source source = addSource(r''' 3311 Source source = addSource(r'''
3556 f(var l) { 3312 f(var l) {
3557 for (e in l) { 3313 for (e in l) {
3558 } 3314 }
3559 }'''); 3315 }''');
3560 computeLibrarySourceErrors(source);
3561 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3316 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3562 } 3317 }
3563 3318
3564 void test_undefinedIdentifier_function() { 3319 void test_undefinedIdentifier_function() {
3565 Source source = addSource("int a() => b;"); 3320 Source source = addSource("int a() => b;");
3566 computeLibrarySourceErrors(source);
3567 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3321 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3568 } 3322 }
3569 3323
3570 void test_undefinedIdentifier_importCore_withShow() { 3324 void test_undefinedIdentifier_importCore_withShow() {
3571 Source source = addSource(r''' 3325 Source source = addSource(r'''
3572 import 'dart:core' show List; 3326 import 'dart:core' show List;
3573 main() { 3327 main() {
3574 List; 3328 List;
3575 String; 3329 String;
3576 }'''); 3330 }''');
3577 computeLibrarySourceErrors(source);
3578 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3331 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3579 } 3332 }
3580 3333
3581 void test_undefinedIdentifier_initializer() { 3334 void test_undefinedIdentifier_initializer() {
3582 Source source = addSource("var a = b;"); 3335 Source source = addSource("var a = b;");
3583 computeLibrarySourceErrors(source);
3584 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3336 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3585 } 3337 }
3586 3338
3587 void test_undefinedIdentifier_methodInvocation() { 3339 void test_undefinedIdentifier_methodInvocation() {
3588 Source source = addSource("f() { C.m(); }"); 3340 Source source = addSource("f() { C.m(); }");
3589 computeLibrarySourceErrors(source);
3590 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3341 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3591 } 3342 }
3592 3343
3593 void test_undefinedIdentifier_private_getter() { 3344 void test_undefinedIdentifier_private_getter() {
3594 addNamedSource( 3345 addNamedSource(
3595 "/lib.dart", 3346 "/lib.dart",
3596 r''' 3347 r'''
3597 library lib; 3348 library lib;
3598 class A { 3349 class A {
3599 var _foo; 3350 var _foo;
3600 }'''); 3351 }''');
3601 Source source = addSource(r''' 3352 Source source = addSource(r'''
3602 import 'lib.dart'; 3353 import 'lib.dart';
3603 class B extends A { 3354 class B extends A {
3604 test() { 3355 test() {
3605 var v = _foo; 3356 var v = _foo;
3606 } 3357 }
3607 }'''); 3358 }''');
3608 computeLibrarySourceErrors(source);
3609 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3359 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3610 } 3360 }
3611 3361
3612 void test_undefinedIdentifier_private_setter() { 3362 void test_undefinedIdentifier_private_setter() {
3613 addNamedSource( 3363 addNamedSource(
3614 "/lib.dart", 3364 "/lib.dart",
3615 r''' 3365 r'''
3616 library lib; 3366 library lib;
3617 class A { 3367 class A {
3618 var _foo; 3368 var _foo;
3619 }'''); 3369 }''');
3620 Source source = addSource(r''' 3370 Source source = addSource(r'''
3621 import 'lib.dart'; 3371 import 'lib.dart';
3622 class B extends A { 3372 class B extends A {
3623 test() { 3373 test() {
3624 _foo = 42; 3374 _foo = 42;
3625 } 3375 }
3626 }'''); 3376 }''');
3627 computeLibrarySourceErrors(source);
3628 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3377 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3629 } 3378 }
3630 3379
3631 void test_undefinedIdentifierAwait_function() { 3380 void test_undefinedIdentifierAwait_function() {
3632 Source source = addSource("void a() { await; }"); 3381 Source source = addSource("void a() { await; }");
3633 computeLibrarySourceErrors(source);
3634 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT]); 3382 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT]);
3635 } 3383 }
3636 3384
3637 void test_undefinedNamedParameter() { 3385 void test_undefinedNamedParameter() {
3638 Source source = addSource(r''' 3386 Source source = addSource(r'''
3639 f({a, b}) {} 3387 f({a, b}) {}
3640 main() { 3388 main() {
3641 f(c: 1); 3389 f(c: 1);
3642 }'''); 3390 }''');
3643 computeLibrarySourceErrors(source);
3644 assertErrors(source, [StaticWarningCode.UNDEFINED_NAMED_PARAMETER]); 3391 assertErrors(source, [StaticWarningCode.UNDEFINED_NAMED_PARAMETER]);
3645 // no verify(), 'c' is not resolved 3392 // no verify(), 'c' is not resolved
3646 } 3393 }
3647 3394
3648 void test_undefinedSetter() { 3395 void test_undefinedSetter() {
3649 Source source1 = addNamedSource("/lib.dart", ""); 3396 addNamedSource("/lib.dart", "");
3650 Source source2 = addNamedSource( 3397 Source source2 = addNamedSource(
3651 "/lib2.dart", 3398 "/lib2.dart",
3652 r''' 3399 r'''
3653 import 'lib.dart' as lib; 3400 import 'lib.dart' as lib;
3654 void f() { 3401 void f() {
3655 lib.gg = null; 3402 lib.gg = null;
3656 }'''); 3403 }''');
3657 computeLibrarySourceErrors(source1);
3658 computeLibrarySourceErrors(source2);
3659 assertErrors(source2, [StaticWarningCode.UNDEFINED_SETTER]); 3404 assertErrors(source2, [StaticWarningCode.UNDEFINED_SETTER]);
3660 } 3405 }
3661 3406
3662 void test_undefinedStaticMethodOrGetter_getter() { 3407 void test_undefinedStaticMethodOrGetter_getter() {
3663 Source source = addSource(r''' 3408 Source source = addSource(r'''
3664 class C {} 3409 class C {}
3665 f(var p) { 3410 f(var p) {
3666 f(C.m); 3411 f(C.m);
3667 }'''); 3412 }''');
3668 computeLibrarySourceErrors(source);
3669 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); 3413 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
3670 } 3414 }
3671 3415
3672 void test_undefinedStaticMethodOrGetter_getter_inSuperclass() { 3416 void test_undefinedStaticMethodOrGetter_getter_inSuperclass() {
3673 Source source = addSource(r''' 3417 Source source = addSource(r'''
3674 class S { 3418 class S {
3675 static int get g => 0; 3419 static int get g => 0;
3676 } 3420 }
3677 class C extends S {} 3421 class C extends S {}
3678 f(var p) { 3422 f(var p) {
3679 f(C.g); 3423 f(C.g);
3680 }'''); 3424 }''');
3681 computeLibrarySourceErrors(source);
3682 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); 3425 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
3683 } 3426 }
3684 3427
3685 void test_undefinedStaticMethodOrGetter_method() { 3428 void test_undefinedStaticMethodOrGetter_method() {
3686 Source source = addSource(r''' 3429 Source source = addSource(r'''
3687 class C {} 3430 class C {}
3688 f(var p) { 3431 f(var p) {
3689 f(C.m()); 3432 f(C.m());
3690 }'''); 3433 }''');
3691 computeLibrarySourceErrors(source);
3692 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); 3434 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
3693 } 3435 }
3694 3436
3695 void test_undefinedStaticMethodOrGetter_method_inSuperclass() { 3437 void test_undefinedStaticMethodOrGetter_method_inSuperclass() {
3696 Source source = addSource(r''' 3438 Source source = addSource(r'''
3697 class S { 3439 class S {
3698 static m() {} 3440 static m() {}
3699 } 3441 }
3700 class C extends S {} 3442 class C extends S {}
3701 f(var p) { 3443 f(var p) {
3702 f(C.m()); 3444 f(C.m());
3703 }'''); 3445 }''');
3704 computeLibrarySourceErrors(source);
3705 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); 3446 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
3706 } 3447 }
3707 3448
3708 void test_undefinedStaticMethodOrGetter_setter_inSuperclass() { 3449 void test_undefinedStaticMethodOrGetter_setter_inSuperclass() {
3709 Source source = addSource(r''' 3450 Source source = addSource(r'''
3710 class S { 3451 class S {
3711 static set s(int i) {} 3452 static set s(int i) {}
3712 } 3453 }
3713 class C extends S {} 3454 class C extends S {}
3714 f(var p) { 3455 f(var p) {
3715 f(C.s = 1); 3456 f(C.s = 1);
3716 }'''); 3457 }''');
3717 computeLibrarySourceErrors(source);
3718 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]); 3458 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]);
3719 } 3459 }
3720 3460
3721 void test_voidReturnForGetter() { 3461 void test_voidReturnForGetter() {
3722 Source source = addSource(r''' 3462 Source source = addSource(r'''
3723 class S { 3463 class S {
3724 void get value {} 3464 void get value {}
3725 }'''); 3465 }''');
3726 computeLibrarySourceErrors(source);
3727 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); 3466 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]);
3728 } 3467 }
3729 } 3468 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/static_type_warning_code_test.dart ('k') | pkg/analyzer/test/generated/strong_mode_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698