OLD | NEW |
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_type_warning_code_test; | 5 library analyzer.test.generated.static_type_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/java_core.dart' show formatList; | 10 import 'package:analyzer/src/generated/java_core.dart' show formatList; |
11 import 'package:analyzer/src/generated/source_io.dart'; | 11 import 'package:analyzer/src/generated/source_io.dart'; |
12 import 'package:test/test.dart'; | 12 import 'package:test/test.dart'; |
13 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
14 | 14 |
15 import 'resolver_test_case.dart'; | 15 import 'resolver_test_case.dart'; |
16 | 16 |
17 main() { | 17 main() { |
18 defineReflectiveSuite(() { | 18 defineReflectiveSuite(() { |
19 defineReflectiveTests(StaticTypeWarningCodeTest); | 19 defineReflectiveTests(StaticTypeWarningCodeTest); |
20 defineReflectiveTests(StrongModeStaticTypeWarningCodeTest); | 20 defineReflectiveTests(StrongModeStaticTypeWarningCodeTest); |
21 }); | 21 }); |
22 } | 22 } |
23 | 23 |
24 @reflectiveTest | 24 @reflectiveTest |
25 class StaticTypeWarningCodeTest extends ResolverTestCase { | 25 class StaticTypeWarningCodeTest extends ResolverTestCase { |
26 fail_method_lookup_mixin_of_extends() async { | 26 fail_method_lookup_mixin_of_extends() async { |
27 // See dartbug.com/25605 | 27 // See dartbug.com/25605 |
28 resetWith(options: new AnalysisOptionsImpl()..enableSuperMixins = true); | 28 resetWith(options: new AnalysisOptionsImpl()..enableSuperMixins = true); |
29 await assertErrorsInUnverifiedCode( | 29 await assertErrorsInUnverifiedCode(''' |
30 ''' | |
31 class A { a() => null; } | 30 class A { a() => null; } |
32 class B {} | 31 class B {} |
33 abstract class M extends A {} | 32 abstract class M extends A {} |
34 class T = B with M; // Warning: B does not extend A | 33 class T = B with M; // Warning: B does not extend A |
35 main() { | 34 main() { |
36 new T().a(); // Warning: The method 'a' is not defined for the class 'T' | 35 new T().a(); // Warning: The method 'a' is not defined for the class 'T' |
37 } | 36 } |
38 ''', | 37 ''', [ |
39 [ | 38 // TODO(paulberry): when dartbug.com/25614 is fixed, add static warning |
40 // TODO(paulberry): when dartbug.com/25614 is fixed, add static warnin
g | 39 // code for "B does not extend A". |
41 // code for "B does not extend A". | 40 StaticTypeWarningCode.UNDEFINED_METHOD |
42 StaticTypeWarningCode.UNDEFINED_METHOD | 41 ]); |
43 ]); | |
44 } | 42 } |
45 | 43 |
46 fail_method_lookup_mixin_of_implements() async { | 44 fail_method_lookup_mixin_of_implements() async { |
47 // See dartbug.com/25605 | 45 // See dartbug.com/25605 |
48 resetWith(options: new AnalysisOptionsImpl()..enableSuperMixins = true); | 46 resetWith(options: new AnalysisOptionsImpl()..enableSuperMixins = true); |
49 await assertErrorsInUnverifiedCode( | 47 await assertErrorsInUnverifiedCode(''' |
50 ''' | |
51 class A { a() => null; } | 48 class A { a() => null; } |
52 class B {} | 49 class B {} |
53 abstract class M implements A {} | 50 abstract class M implements A {} |
54 class T = B with M; // Warning: Missing concrete implementation of 'A.a' | 51 class T = B with M; // Warning: Missing concrete implementation of 'A.a' |
55 main() { | 52 main() { |
56 new T().a(); // Warning: The method 'a' is not defined for the class 'T' | 53 new T().a(); // Warning: The method 'a' is not defined for the class 'T' |
57 } | 54 } |
58 ''', | 55 ''', [ |
59 [ | 56 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, |
60 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, | 57 StaticTypeWarningCode.UNDEFINED_METHOD |
61 StaticTypeWarningCode.UNDEFINED_METHOD | 58 ]); |
62 ]); | |
63 } | 59 } |
64 | 60 |
65 fail_method_lookup_mixin_of_mixin() async { | 61 fail_method_lookup_mixin_of_mixin() async { |
66 // See dartbug.com/25605 | 62 // See dartbug.com/25605 |
67 resetWith(options: new AnalysisOptionsImpl()..enableSuperMixins = true); | 63 resetWith(options: new AnalysisOptionsImpl()..enableSuperMixins = true); |
68 await assertErrorsInUnverifiedCode( | 64 await assertErrorsInUnverifiedCode(''' |
69 ''' | |
70 class A {} | 65 class A {} |
71 class B { b() => null; } | 66 class B { b() => null; } |
72 class C {} | 67 class C {} |
73 class M extends A with B {} | 68 class M extends A with B {} |
74 class T = C with M; | 69 class T = C with M; |
75 main() { | 70 main() { |
76 new T().b(); | 71 new T().b(); |
77 } | 72 } |
78 ''', | 73 ''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
79 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
80 } | 74 } |
81 | 75 |
82 fail_method_lookup_mixin_of_mixin_application() async { | 76 fail_method_lookup_mixin_of_mixin_application() async { |
83 // See dartbug.com/25605 | 77 // See dartbug.com/25605 |
84 resetWith(options: new AnalysisOptionsImpl()..enableSuperMixins = true); | 78 resetWith(options: new AnalysisOptionsImpl()..enableSuperMixins = true); |
85 await assertErrorsInUnverifiedCode( | 79 await assertErrorsInUnverifiedCode(''' |
86 ''' | |
87 class A { a() => null; } | 80 class A { a() => null; } |
88 class B {} | 81 class B {} |
89 class C {} | 82 class C {} |
90 class M = A with B; | 83 class M = A with B; |
91 class T = C with M; | 84 class T = C with M; |
92 main() { | 85 main() { |
93 new T().a(); | 86 new T().a(); |
94 } | 87 } |
95 ''', | 88 ''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
96 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
97 } | 89 } |
98 | 90 |
99 fail_typeArgumentNotMatchingBounds_ofFunctionTypeAlias() async { | 91 fail_typeArgumentNotMatchingBounds_ofFunctionTypeAlias() async { |
100 await assertErrorsInCode( | 92 await assertErrorsInCode(r''' |
101 r''' | |
102 class A {} | 93 class A {} |
103 class B {} | 94 class B {} |
104 typedef F<T extends A>(); | 95 typedef F<T extends A>(); |
105 F<B> fff; | 96 F<B> fff; |
106 ''', | 97 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
107 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
108 } | 98 } |
109 | 99 |
110 fail_undefinedEnumConstant() async { | 100 fail_undefinedEnumConstant() async { |
111 // We need a way to set the parseEnum flag in the parser to true. | 101 // We need a way to set the parseEnum flag in the parser to true. |
112 await assertErrorsInCode( | 102 await assertErrorsInCode(r''' |
113 r''' | |
114 enum E { ONE } | 103 enum E { ONE } |
115 E e() { | 104 E e() { |
116 return E.TWO; | 105 return E.TWO; |
117 }''', | 106 }''', [StaticTypeWarningCode.UNDEFINED_ENUM_CONSTANT]); |
118 [StaticTypeWarningCode.UNDEFINED_ENUM_CONSTANT]); | |
119 } | 107 } |
120 | 108 |
121 test_ambiguousImport_function() async { | 109 test_ambiguousImport_function() async { |
122 Source source = addSource(r''' | 110 Source source = addSource(r''' |
123 import 'lib1.dart'; | 111 import 'lib1.dart'; |
124 import 'lib2.dart'; | 112 import 'lib2.dart'; |
125 g() { return f(); }'''); | 113 g() { return f(); }'''); |
126 addNamedSource( | 114 addNamedSource("/lib1.dart", r''' |
127 "/lib1.dart", | |
128 r''' | |
129 library lib1; | 115 library lib1; |
130 f() {}'''); | 116 f() {}'''); |
131 addNamedSource( | 117 addNamedSource("/lib2.dart", r''' |
132 "/lib2.dart", | |
133 r''' | |
134 library lib2; | 118 library lib2; |
135 f() {}'''); | 119 f() {}'''); |
136 await computeAnalysisResult(source); | 120 await computeAnalysisResult(source); |
137 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); | 121 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); |
138 } | 122 } |
139 | 123 |
140 test_assert_message_suppresses_type_promotion() async { | 124 test_assert_message_suppresses_type_promotion() async { |
141 // If a variable is assigned to inside the expression for an assert | 125 // If a variable is assigned to inside the expression for an assert |
142 // message, type promotion should be suppressed, just as it would be if the | 126 // message, type promotion should be suppressed, just as it would be if the |
143 // assignment occurred outside an assert statement. (Note that it is a | 127 // assignment occurred outside an assert statement. (Note that it is a |
144 // dubious practice for the computation of an assert message to have side | 128 // dubious practice for the computation of an assert message to have side |
145 // effects, since it is only evaluated if the assert fails). | 129 // effects, since it is only evaluated if the assert fails). |
146 await assertErrorsInCode( | 130 await assertErrorsInCode(''' |
147 ''' | |
148 class C { | 131 class C { |
149 void foo() {} | 132 void foo() {} |
150 } | 133 } |
151 | 134 |
152 f(Object x) { | 135 f(Object x) { |
153 if (x is C) { | 136 if (x is C) { |
154 x.foo(); | 137 x.foo(); |
155 assert(true, () { x = new C(); return 'msg'; }()); | 138 assert(true, () { x = new C(); return 'msg'; }()); |
156 } | 139 } |
157 } | 140 } |
158 ''', | 141 ''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
159 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
160 // Do not verify since `x.foo()` fails to resolve. | 142 // Do not verify since `x.foo()` fails to resolve. |
161 } | 143 } |
162 | 144 |
163 test_await_flattened() async { | 145 test_await_flattened() async { |
164 await assertErrorsInCode( | 146 await assertErrorsInCode(''' |
165 ''' | |
166 import 'dart:async'; | 147 import 'dart:async'; |
167 Future<Future<int>> ffi() => null; | 148 Future<Future<int>> ffi() => null; |
168 f() async { | 149 f() async { |
169 Future<int> b = await ffi(); // Warning: int not assignable to Future<int> | 150 Future<int> b = await ffi(); // Warning: int not assignable to Future<int> |
170 } | 151 } |
171 ''', | 152 ''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
172 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
173 } | 153 } |
174 | 154 |
175 test_await_simple() async { | 155 test_await_simple() async { |
176 await assertErrorsInCode( | 156 await assertErrorsInCode(''' |
177 ''' | |
178 import 'dart:async'; | 157 import 'dart:async'; |
179 Future<int> fi() => null; | 158 Future<int> fi() => null; |
180 f() async { | 159 f() async { |
181 String a = await fi(); // Warning: int not assignable to String | 160 String a = await fi(); // Warning: int not assignable to String |
182 } | 161 } |
183 ''', | 162 ''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
184 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
185 } | 163 } |
186 | 164 |
187 test_awaitForIn_declaredVariableRightType() async { | 165 test_awaitForIn_declaredVariableRightType() async { |
188 await assertNoErrorsInCode(''' | 166 await assertNoErrorsInCode(''' |
189 import 'dart:async'; | 167 import 'dart:async'; |
190 f() async { | 168 f() async { |
191 Stream<int> stream; | 169 Stream<int> stream; |
192 await for (int i in stream) {} | 170 await for (int i in stream) {} |
193 } | 171 } |
194 '''); | 172 '''); |
195 } | 173 } |
196 | 174 |
197 test_awaitForIn_declaredVariableWrongType() async { | 175 test_awaitForIn_declaredVariableWrongType() async { |
198 await assertErrorsInCode( | 176 await assertErrorsInCode(''' |
199 ''' | |
200 import 'dart:async'; | 177 import 'dart:async'; |
201 f() async { | 178 f() async { |
202 Stream<String> stream; | 179 Stream<String> stream; |
203 await for (int i in stream) {} | 180 await for (int i in stream) {} |
204 } | 181 } |
205 ''', | 182 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); |
206 [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); | |
207 } | 183 } |
208 | 184 |
209 test_awaitForIn_downcast() async { | 185 test_awaitForIn_downcast() async { |
210 await assertNoErrorsInCode(''' | 186 await assertNoErrorsInCode(''' |
211 import 'dart:async'; | 187 import 'dart:async'; |
212 f() async { | 188 f() async { |
213 Stream<num> stream; | 189 Stream<num> stream; |
214 await for (int i in stream) {} | 190 await for (int i in stream) {} |
215 } | 191 } |
216 '''); | 192 '''); |
(...skipping 23 matching lines...) Expand all Loading... |
240 import 'dart:async'; | 216 import 'dart:async'; |
241 f() async { | 217 f() async { |
242 Stream<int> stream; | 218 Stream<int> stream; |
243 int i; | 219 int i; |
244 await for (i in stream) {} | 220 await for (i in stream) {} |
245 } | 221 } |
246 '''); | 222 '''); |
247 } | 223 } |
248 | 224 |
249 test_awaitForIn_existingVariableWrongType() async { | 225 test_awaitForIn_existingVariableWrongType() async { |
250 await assertErrorsInCode( | 226 await assertErrorsInCode(''' |
251 ''' | |
252 import 'dart:async'; | 227 import 'dart:async'; |
253 f() async { | 228 f() async { |
254 Stream<String> stream; | 229 Stream<String> stream; |
255 int i; | 230 int i; |
256 await for (i in stream) {} | 231 await for (i in stream) {} |
257 } | 232 } |
258 ''', | 233 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); |
259 [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); | |
260 } | 234 } |
261 | 235 |
262 test_awaitForIn_notStream() async { | 236 test_awaitForIn_notStream() async { |
263 await assertErrorsInCode( | 237 await assertErrorsInCode(''' |
264 ''' | |
265 f() async { | 238 f() async { |
266 await for (var i in true) {} | 239 await for (var i in true) {} |
267 } | 240 } |
268 ''', | 241 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]); |
269 [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]); | |
270 } | 242 } |
271 | 243 |
272 test_awaitForIn_streamOfDynamic() async { | 244 test_awaitForIn_streamOfDynamic() async { |
273 await assertNoErrorsInCode(''' | 245 await assertNoErrorsInCode(''' |
274 import 'dart:async'; | 246 import 'dart:async'; |
275 f() async { | 247 f() async { |
276 Stream stream; | 248 Stream stream; |
277 await for (int i in stream) {} | 249 await for (int i in stream) {} |
278 } | 250 } |
279 '''); | 251 '''); |
280 } | 252 } |
281 | 253 |
282 test_awaitForIn_upcast() async { | 254 test_awaitForIn_upcast() async { |
283 await assertNoErrorsInCode(''' | 255 await assertNoErrorsInCode(''' |
284 import 'dart:async'; | 256 import 'dart:async'; |
285 f() async { | 257 f() async { |
286 Stream<int> stream; | 258 Stream<int> stream; |
287 await for (num i in stream) {} | 259 await for (num i in stream) {} |
288 } | 260 } |
289 '''); | 261 '''); |
290 } | 262 } |
291 | 263 |
292 test_bug21912() async { | 264 test_bug21912() async { |
293 await assertErrorsInCode( | 265 await assertErrorsInCode(''' |
294 ''' | |
295 class A {} | 266 class A {} |
296 class B extends A {} | 267 class B extends A {} |
297 | 268 |
298 typedef T Function2<S, T>(S z); | 269 typedef T Function2<S, T>(S z); |
299 typedef B AToB(A x); | 270 typedef B AToB(A x); |
300 typedef A BToA(B x); | 271 typedef A BToA(B x); |
301 | 272 |
302 void main() { | 273 void main() { |
303 { | 274 { |
304 Function2<Function2<A, B>, Function2<B, A>> t1; | 275 Function2<Function2<A, B>, Function2<B, A>> t1; |
305 Function2<AToB, BToA> t2; | 276 Function2<AToB, BToA> t2; |
306 | 277 |
307 Function2<Function2<int, double>, Function2<int, double>> left; | 278 Function2<Function2<int, double>, Function2<int, double>> left; |
308 | 279 |
309 left = t1; | 280 left = t1; |
310 left = t2; | 281 left = t2; |
311 } | 282 } |
312 } | 283 } |
313 ''', | 284 ''', [ |
314 [ | 285 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
315 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 286 StaticTypeWarningCode.INVALID_ASSIGNMENT |
316 StaticTypeWarningCode.INVALID_ASSIGNMENT | 287 ]); |
317 ]); | |
318 } | 288 } |
319 | 289 |
320 test_expectedOneListTypeArgument() async { | 290 test_expectedOneListTypeArgument() async { |
321 await assertErrorsInCode( | 291 await assertErrorsInCode(r''' |
322 r''' | |
323 main() { | 292 main() { |
324 <int, int> []; | 293 <int, int> []; |
325 }''', | 294 }''', [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]); |
326 [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]); | |
327 } | 295 } |
328 | 296 |
329 test_expectedTwoMapTypeArguments_one() async { | 297 test_expectedTwoMapTypeArguments_one() async { |
330 await assertErrorsInCode( | 298 await assertErrorsInCode(r''' |
331 r''' | |
332 main() { | 299 main() { |
333 <int> {}; | 300 <int> {}; |
334 }''', | 301 }''', [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]); |
335 [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]); | |
336 } | 302 } |
337 | 303 |
338 test_expectedTwoMapTypeArguments_three() async { | 304 test_expectedTwoMapTypeArguments_three() async { |
339 await assertErrorsInCode( | 305 await assertErrorsInCode(r''' |
340 r''' | |
341 main() { | 306 main() { |
342 <int, int, int> {}; | 307 <int, int, int> {}; |
343 }''', | 308 }''', [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]); |
344 [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]); | |
345 } | 309 } |
346 | 310 |
347 test_forIn_declaredVariableRightType() async { | 311 test_forIn_declaredVariableRightType() async { |
348 await assertNoErrorsInCode(''' | 312 await assertNoErrorsInCode(''' |
349 f() { | 313 f() { |
350 for (int i in <int>[]) {} | 314 for (int i in <int>[]) {} |
351 } | 315 } |
352 '''); | 316 '''); |
353 } | 317 } |
354 | 318 |
355 test_forIn_declaredVariableWrongType() async { | 319 test_forIn_declaredVariableWrongType() async { |
356 await assertErrorsInCode( | 320 await assertErrorsInCode(''' |
357 ''' | |
358 f() { | 321 f() { |
359 for (int i in <String>[]) {} | 322 for (int i in <String>[]) {} |
360 } | 323 } |
361 ''', | 324 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); |
362 [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); | |
363 } | 325 } |
364 | 326 |
365 test_forIn_downcast() async { | 327 test_forIn_downcast() async { |
366 await assertNoErrorsInCode(''' | 328 await assertNoErrorsInCode(''' |
367 f() { | 329 f() { |
368 for (int i in <num>[]) {} | 330 for (int i in <num>[]) {} |
369 } | 331 } |
370 '''); | 332 '''); |
371 } | 333 } |
372 | 334 |
(...skipping 26 matching lines...) Expand all Loading... |
399 test_forIn_existingVariableRightType() async { | 361 test_forIn_existingVariableRightType() async { |
400 await assertNoErrorsInCode(''' | 362 await assertNoErrorsInCode(''' |
401 f() { | 363 f() { |
402 int i; | 364 int i; |
403 for (i in <int>[]) {} | 365 for (i in <int>[]) {} |
404 } | 366 } |
405 '''); | 367 '''); |
406 } | 368 } |
407 | 369 |
408 test_forIn_existingVariableWrongType() async { | 370 test_forIn_existingVariableWrongType() async { |
409 await assertErrorsInCode( | 371 await assertErrorsInCode(''' |
410 ''' | |
411 f() { | 372 f() { |
412 int i; | 373 int i; |
413 for (i in <String>[]) {} | 374 for (i in <String>[]) {} |
414 } | 375 } |
415 ''', | 376 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); |
416 [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); | |
417 } | 377 } |
418 | 378 |
419 test_forIn_iterableOfDynamic() async { | 379 test_forIn_iterableOfDynamic() async { |
420 await assertNoErrorsInCode(''' | 380 await assertNoErrorsInCode(''' |
421 f() { | 381 f() { |
422 for (int i in []) {} | 382 for (int i in []) {} |
423 } | 383 } |
424 '''); | 384 '''); |
425 } | 385 } |
426 | 386 |
427 test_forIn_notIterable() async { | 387 test_forIn_notIterable() async { |
428 await assertErrorsInCode( | 388 await assertErrorsInCode(''' |
429 ''' | |
430 f() { | 389 f() { |
431 for (var i in true) {} | 390 for (var i in true) {} |
432 } | 391 } |
433 ''', | 392 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]); |
434 [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]); | |
435 } | 393 } |
436 | 394 |
437 test_forIn_object() async { | 395 test_forIn_object() async { |
438 await assertNoErrorsInCode(''' | 396 await assertNoErrorsInCode(''' |
439 f() { | 397 f() { |
440 Object o; // Could be []. | 398 Object o; // Could be []. |
441 for (var i in o) {} | 399 for (var i in o) {} |
442 } | 400 } |
443 '''); | 401 '''); |
444 } | 402 } |
445 | 403 |
446 test_forIn_typeBoundBad() async { | 404 test_forIn_typeBoundBad() async { |
447 await assertErrorsInCode( | 405 await assertErrorsInCode(''' |
448 ''' | |
449 class Foo<T extends Iterable<int>> { | 406 class Foo<T extends Iterable<int>> { |
450 void method(T iterable) { | 407 void method(T iterable) { |
451 for (String i in iterable) {} | 408 for (String i in iterable) {} |
452 } | 409 } |
453 } | 410 } |
454 ''', | 411 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); |
455 [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]); | |
456 } | 412 } |
457 | 413 |
458 test_forIn_typeBoundGood() async { | 414 test_forIn_typeBoundGood() async { |
459 await assertNoErrorsInCode(''' | 415 await assertNoErrorsInCode(''' |
460 class Foo<T extends Iterable<int>> { | 416 class Foo<T extends Iterable<int>> { |
461 void method(T iterable) { | 417 void method(T iterable) { |
462 for (var i in iterable) {} | 418 for (var i in iterable) {} |
463 } | 419 } |
464 } | 420 } |
465 '''); | 421 '''); |
466 } | 422 } |
467 | 423 |
468 test_forIn_upcast() async { | 424 test_forIn_upcast() async { |
469 await assertNoErrorsInCode(''' | 425 await assertNoErrorsInCode(''' |
470 f() { | 426 f() { |
471 for (num i in <int>[]) {} | 427 for (num i in <int>[]) {} |
472 } | 428 } |
473 '''); | 429 '''); |
474 } | 430 } |
475 | 431 |
476 test_illegalAsyncGeneratorReturnType_function_nonStream() async { | 432 test_illegalAsyncGeneratorReturnType_function_nonStream() async { |
477 await assertErrorsInCode( | 433 await assertErrorsInCode(''' |
478 ''' | |
479 int f() async* {} | 434 int f() async* {} |
480 ''', | 435 ''', [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]); |
481 [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]); | |
482 } | 436 } |
483 | 437 |
484 test_illegalAsyncGeneratorReturnType_function_subtypeOfStream() async { | 438 test_illegalAsyncGeneratorReturnType_function_subtypeOfStream() async { |
485 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 439 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
486 await assertErrorsInCode( | 440 await assertErrorsInCode(''' |
487 ''' | |
488 import 'dart:async'; | 441 import 'dart:async'; |
489 abstract class SubStream<T> implements Stream<T> {} | 442 abstract class SubStream<T> implements Stream<T> {} |
490 SubStream<int> f() async* {} | 443 SubStream<int> f() async* {} |
491 ''', | 444 ''', [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]); |
492 [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]); | |
493 } | 445 } |
494 | 446 |
495 test_illegalAsyncGeneratorReturnType_method_nonStream() async { | 447 test_illegalAsyncGeneratorReturnType_method_nonStream() async { |
496 await assertErrorsInCode( | 448 await assertErrorsInCode(''' |
497 ''' | |
498 class C { | 449 class C { |
499 int f() async* {} | 450 int f() async* {} |
500 } | 451 } |
501 ''', | 452 ''', [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]); |
502 [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]); | |
503 } | 453 } |
504 | 454 |
505 test_illegalAsyncGeneratorReturnType_method_subtypeOfStream() async { | 455 test_illegalAsyncGeneratorReturnType_method_subtypeOfStream() async { |
506 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 456 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
507 await assertErrorsInCode( | 457 await assertErrorsInCode(''' |
508 ''' | |
509 import 'dart:async'; | 458 import 'dart:async'; |
510 abstract class SubStream<T> implements Stream<T> {} | 459 abstract class SubStream<T> implements Stream<T> {} |
511 class C { | 460 class C { |
512 SubStream<int> f() async* {} | 461 SubStream<int> f() async* {} |
513 } | 462 } |
514 ''', | 463 ''', [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]); |
515 [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]); | |
516 } | 464 } |
517 | 465 |
518 test_illegalAsyncReturnType_function_nonFuture() async { | 466 test_illegalAsyncReturnType_function_nonFuture() async { |
519 await assertErrorsInCode( | 467 await assertErrorsInCode(''' |
520 ''' | |
521 int f() async {} | 468 int f() async {} |
522 ''', | 469 ''', [ |
523 [ | 470 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, |
524 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, | 471 HintCode.MISSING_RETURN |
525 HintCode.MISSING_RETURN | 472 ]); |
526 ]); | |
527 } | 473 } |
528 | 474 |
529 test_illegalAsyncReturnType_function_subtypeOfFuture() async { | 475 test_illegalAsyncReturnType_function_subtypeOfFuture() async { |
530 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 476 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
531 await assertErrorsInCode( | 477 await assertErrorsInCode(''' |
532 ''' | |
533 import 'dart:async'; | 478 import 'dart:async'; |
534 abstract class SubFuture<T> implements Future<T> {} | 479 abstract class SubFuture<T> implements Future<T> {} |
535 SubFuture<int> f() async { | 480 SubFuture<int> f() async { |
536 return 0; | 481 return 0; |
537 } | 482 } |
538 ''', | 483 ''', [StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE]); |
539 [StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE]); | |
540 } | 484 } |
541 | 485 |
542 test_illegalAsyncReturnType_method_nonFuture() async { | 486 test_illegalAsyncReturnType_method_nonFuture() async { |
543 await assertErrorsInCode( | 487 await assertErrorsInCode(''' |
544 ''' | |
545 class C { | 488 class C { |
546 int m() async {} | 489 int m() async {} |
547 } | 490 } |
548 ''', | 491 ''', [ |
549 [ | 492 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, |
550 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, | 493 HintCode.MISSING_RETURN |
551 HintCode.MISSING_RETURN | 494 ]); |
552 ]); | |
553 } | 495 } |
554 | 496 |
555 test_illegalAsyncReturnType_method_subtypeOfFuture() async { | 497 test_illegalAsyncReturnType_method_subtypeOfFuture() async { |
556 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 498 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
557 await assertErrorsInCode( | 499 await assertErrorsInCode(''' |
558 ''' | |
559 import 'dart:async'; | 500 import 'dart:async'; |
560 abstract class SubFuture<T> implements Future<T> {} | 501 abstract class SubFuture<T> implements Future<T> {} |
561 class C { | 502 class C { |
562 SubFuture<int> m() async { | 503 SubFuture<int> m() async { |
563 return 0; | 504 return 0; |
564 } | 505 } |
565 } | 506 } |
566 ''', | 507 ''', [StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE]); |
567 [StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE]); | |
568 } | 508 } |
569 | 509 |
570 test_illegalSyncGeneratorReturnType_function_nonIterator() async { | 510 test_illegalSyncGeneratorReturnType_function_nonIterator() async { |
571 await assertErrorsInCode( | 511 await assertErrorsInCode(''' |
572 ''' | |
573 int f() sync* {} | 512 int f() sync* {} |
574 ''', | 513 ''', [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]); |
575 [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]); | |
576 } | 514 } |
577 | 515 |
578 test_illegalSyncGeneratorReturnType_function_subclassOfIterator() async { | 516 test_illegalSyncGeneratorReturnType_function_subclassOfIterator() async { |
579 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 517 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
580 await assertErrorsInCode( | 518 await assertErrorsInCode(''' |
581 ''' | |
582 abstract class SubIterator<T> implements Iterator<T> {} | 519 abstract class SubIterator<T> implements Iterator<T> {} |
583 SubIterator<int> f() sync* {} | 520 SubIterator<int> f() sync* {} |
584 ''', | 521 ''', [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]); |
585 [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]); | |
586 } | 522 } |
587 | 523 |
588 test_illegalSyncGeneratorReturnType_method_nonIterator() async { | 524 test_illegalSyncGeneratorReturnType_method_nonIterator() async { |
589 await assertErrorsInCode( | 525 await assertErrorsInCode(''' |
590 ''' | |
591 class C { | 526 class C { |
592 int f() sync* {} | 527 int f() sync* {} |
593 } | 528 } |
594 ''', | 529 ''', [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]); |
595 [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]); | |
596 } | 530 } |
597 | 531 |
598 test_illegalSyncGeneratorReturnType_method_subclassOfIterator() async { | 532 test_illegalSyncGeneratorReturnType_method_subclassOfIterator() async { |
599 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 533 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
600 await assertErrorsInCode( | 534 await assertErrorsInCode(''' |
601 ''' | |
602 abstract class SubIterator<T> implements Iterator<T> {} | 535 abstract class SubIterator<T> implements Iterator<T> {} |
603 class C { | 536 class C { |
604 SubIterator<int> f() sync* {} | 537 SubIterator<int> f() sync* {} |
605 } | 538 } |
606 ''', | 539 ''', [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]); |
607 [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]); | |
608 } | 540 } |
609 | 541 |
610 test_inconsistentMethodInheritance_paramCount() async { | 542 test_inconsistentMethodInheritance_paramCount() async { |
611 await assertErrorsInCode( | 543 await assertErrorsInCode(r''' |
612 r''' | |
613 abstract class A { | 544 abstract class A { |
614 int x(); | 545 int x(); |
615 } | 546 } |
616 abstract class B { | 547 abstract class B { |
617 int x(int y); | 548 int x(int y); |
618 } | 549 } |
619 class C implements A, B { | 550 class C implements A, B { |
620 }''', | 551 }''', [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); |
621 [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); | |
622 } | 552 } |
623 | 553 |
624 test_inconsistentMethodInheritance_paramType() async { | 554 test_inconsistentMethodInheritance_paramType() async { |
625 await assertErrorsInCode( | 555 await assertErrorsInCode(r''' |
626 r''' | |
627 abstract class A { | 556 abstract class A { |
628 x(int i); | 557 x(int i); |
629 } | 558 } |
630 abstract class B { | 559 abstract class B { |
631 x(String s); | 560 x(String s); |
632 } | 561 } |
633 abstract class C implements A, B {} | 562 abstract class C implements A, B {} |
634 ''', | 563 ''', [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); |
635 [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); | |
636 } | 564 } |
637 | 565 |
638 test_inconsistentMethodInheritance_returnType() async { | 566 test_inconsistentMethodInheritance_returnType() async { |
639 await assertErrorsInCode( | 567 await assertErrorsInCode(r''' |
640 r''' | |
641 abstract class A { | 568 abstract class A { |
642 int x(); | 569 int x(); |
643 } | 570 } |
644 abstract class B { | 571 abstract class B { |
645 String x(); | 572 String x(); |
646 } | 573 } |
647 abstract class C implements A, B {} | 574 abstract class C implements A, B {} |
648 ''', | 575 ''', [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); |
649 [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); | |
650 } | 576 } |
651 | 577 |
652 test_instanceAccessToStaticMember_method_invocation() async { | 578 test_instanceAccessToStaticMember_method_invocation() async { |
653 await assertErrorsInCode( | 579 await assertErrorsInCode(r''' |
654 r''' | |
655 class A { | 580 class A { |
656 static m() {} | 581 static m() {} |
657 } | 582 } |
658 main(A a) { | 583 main(A a) { |
659 a.m(); | 584 a.m(); |
660 }''', | 585 }''', [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); |
661 [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); | |
662 } | 586 } |
663 | 587 |
664 test_instanceAccessToStaticMember_method_reference() async { | 588 test_instanceAccessToStaticMember_method_reference() async { |
665 await assertErrorsInCode( | 589 await assertErrorsInCode(r''' |
666 r''' | |
667 class A { | 590 class A { |
668 static m() {} | 591 static m() {} |
669 } | 592 } |
670 main(A a) { | 593 main(A a) { |
671 a.m; | 594 a.m; |
672 }''', | 595 }''', [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); |
673 [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); | |
674 } | 596 } |
675 | 597 |
676 test_instanceAccessToStaticMember_propertyAccess_field() async { | 598 test_instanceAccessToStaticMember_propertyAccess_field() async { |
677 await assertErrorsInCode( | 599 await assertErrorsInCode(r''' |
678 r''' | |
679 class A { | 600 class A { |
680 static var f; | 601 static var f; |
681 } | 602 } |
682 main(A a) { | 603 main(A a) { |
683 a.f; | 604 a.f; |
684 }''', | 605 }''', [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); |
685 [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); | |
686 } | 606 } |
687 | 607 |
688 test_instanceAccessToStaticMember_propertyAccess_getter() async { | 608 test_instanceAccessToStaticMember_propertyAccess_getter() async { |
689 await assertErrorsInCode( | 609 await assertErrorsInCode(r''' |
690 r''' | |
691 class A { | 610 class A { |
692 static get f => 42; | 611 static get f => 42; |
693 } | 612 } |
694 main(A a) { | 613 main(A a) { |
695 a.f; | 614 a.f; |
696 }''', | 615 }''', [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); |
697 [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); | |
698 } | 616 } |
699 | 617 |
700 test_instanceAccessToStaticMember_propertyAccess_setter() async { | 618 test_instanceAccessToStaticMember_propertyAccess_setter() async { |
701 await assertErrorsInCode( | 619 await assertErrorsInCode(r''' |
702 r''' | |
703 class A { | 620 class A { |
704 static set f(x) {} | 621 static set f(x) {} |
705 } | 622 } |
706 main(A a) { | 623 main(A a) { |
707 a.f = 42; | 624 a.f = 42; |
708 }''', | 625 }''', [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); |
709 [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]); | |
710 } | 626 } |
711 | 627 |
712 test_invalidAssignment_compoundAssignment() async { | 628 test_invalidAssignment_compoundAssignment() async { |
713 await assertErrorsInCode( | 629 await assertErrorsInCode(r''' |
714 r''' | |
715 class byte { | 630 class byte { |
716 int _value; | 631 int _value; |
717 byte(this._value); | 632 byte(this._value); |
718 int operator +(int val) { return 0; } | 633 int operator +(int val) { return 0; } |
719 } | 634 } |
720 | 635 |
721 void main() { | 636 void main() { |
722 byte b = new byte(52); | 637 byte b = new byte(52); |
723 b += 3; | 638 b += 3; |
724 }''', | 639 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
725 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
726 } | 640 } |
727 | 641 |
728 test_invalidAssignment_defaultValue_named() async { | 642 test_invalidAssignment_defaultValue_named() async { |
729 await assertErrorsInCode( | 643 await assertErrorsInCode(r''' |
730 r''' | |
731 f({String x: 0}) { | 644 f({String x: 0}) { |
732 }''', | 645 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
733 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
734 } | 646 } |
735 | 647 |
736 test_invalidAssignment_defaultValue_optional() async { | 648 test_invalidAssignment_defaultValue_optional() async { |
737 await assertErrorsInCode( | 649 await assertErrorsInCode(r''' |
738 r''' | |
739 f([String x = 0]) { | 650 f([String x = 0]) { |
740 }''', | 651 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
741 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
742 } | 652 } |
743 | 653 |
744 test_invalidAssignment_dynamic() async { | 654 test_invalidAssignment_dynamic() async { |
745 await assertErrorsInCode( | 655 await assertErrorsInCode(r''' |
746 r''' | |
747 main() { | 656 main() { |
748 dynamic = 1; | 657 dynamic = 1; |
749 } | 658 } |
750 ''', | 659 ''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
751 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
752 } | 660 } |
753 | 661 |
754 test_invalidAssignment_functionExpressionInvocation() async { | 662 test_invalidAssignment_functionExpressionInvocation() async { |
755 await assertErrorsInCode( | 663 await assertErrorsInCode(''' |
756 ''' | |
757 main() { | 664 main() { |
758 String x = (() => 5)(); | 665 String x = (() => 5)(); |
759 }''', | 666 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
760 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
761 } | 667 } |
762 | 668 |
763 test_invalidAssignment_ifNullAssignment() async { | 669 test_invalidAssignment_ifNullAssignment() async { |
764 await assertErrorsInCode( | 670 await assertErrorsInCode(''' |
765 ''' | |
766 void f(int i) { | 671 void f(int i) { |
767 double d; | 672 double d; |
768 d ??= i; | 673 d ??= i; |
769 } | 674 } |
770 ''', | 675 ''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
771 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
772 } | 676 } |
773 | 677 |
774 test_invalidAssignment_instanceVariable() async { | 678 test_invalidAssignment_instanceVariable() async { |
775 await assertErrorsInCode( | 679 await assertErrorsInCode(r''' |
776 r''' | |
777 class A { | 680 class A { |
778 int x; | 681 int x; |
779 } | 682 } |
780 f() { | 683 f() { |
781 A a; | 684 A a; |
782 a.x = '0'; | 685 a.x = '0'; |
783 }''', | 686 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
784 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
785 } | 687 } |
786 | 688 |
787 test_invalidAssignment_localVariable() async { | 689 test_invalidAssignment_localVariable() async { |
788 await assertErrorsInCode( | 690 await assertErrorsInCode(r''' |
789 r''' | |
790 f() { | 691 f() { |
791 int x; | 692 int x; |
792 x = '0'; | 693 x = '0'; |
793 }''', | 694 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
794 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
795 } | 695 } |
796 | 696 |
797 test_invalidAssignment_regressionInIssue18468Fix() async { | 697 test_invalidAssignment_regressionInIssue18468Fix() async { |
798 // https://code.google.com/p/dart/issues/detail?id=18628 | 698 // https://code.google.com/p/dart/issues/detail?id=18628 |
799 await assertErrorsInCode( | 699 await assertErrorsInCode(r''' |
800 r''' | |
801 class C<T> { | 700 class C<T> { |
802 T t = int; | 701 T t = int; |
803 }''', | 702 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
804 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
805 } | 703 } |
806 | 704 |
807 test_invalidAssignment_staticVariable() async { | 705 test_invalidAssignment_staticVariable() async { |
808 await assertErrorsInCode( | 706 await assertErrorsInCode(r''' |
809 r''' | |
810 class A { | 707 class A { |
811 static int x; | 708 static int x; |
812 } | 709 } |
813 f() { | 710 f() { |
814 A.x = '0'; | 711 A.x = '0'; |
815 }''', | 712 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
816 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
817 } | 713 } |
818 | 714 |
819 test_invalidAssignment_topLevelVariableDeclaration() async { | 715 test_invalidAssignment_topLevelVariableDeclaration() async { |
820 await assertErrorsInCode( | 716 await assertErrorsInCode( |
821 "int x = 'string';", [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 717 "int x = 'string';", [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
822 } | 718 } |
823 | 719 |
824 test_invalidAssignment_typeParameter() async { | 720 test_invalidAssignment_typeParameter() async { |
825 // 14221 | 721 // 14221 |
826 await assertErrorsInCode( | 722 await assertErrorsInCode(r''' |
827 r''' | |
828 class B<T> { | 723 class B<T> { |
829 T value; | 724 T value; |
830 void test(num n) { | 725 void test(num n) { |
831 value = n; | 726 value = n; |
832 } | 727 } |
833 }''', | 728 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
834 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
835 } | 729 } |
836 | 730 |
837 test_invalidAssignment_variableDeclaration() async { | 731 test_invalidAssignment_variableDeclaration() async { |
838 await assertErrorsInCode( | 732 await assertErrorsInCode(r''' |
839 r''' | |
840 class A { | 733 class A { |
841 int x = 'string'; | 734 int x = 'string'; |
842 }''', | 735 }''', [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
843 [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | |
844 } | 736 } |
845 | 737 |
846 test_invocationOfNonFunction_class() async { | 738 test_invocationOfNonFunction_class() async { |
847 await assertErrorsInCode( | 739 await assertErrorsInCode(r''' |
848 r''' | |
849 class A { | 740 class A { |
850 void m() { | 741 void m() { |
851 A(); | 742 A(); |
852 } | 743 } |
853 }''', | 744 }''', [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); |
854 [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); | |
855 } | 745 } |
856 | 746 |
857 test_invocationOfNonFunction_localGenericFunction() async { | 747 test_invocationOfNonFunction_localGenericFunction() async { |
858 // Objects having a specific function type may be invoked, but objects | 748 // Objects having a specific function type may be invoked, but objects |
859 // having type Function may not, because type Function lacks a call method | 749 // having type Function may not, because type Function lacks a call method |
860 // (this is because it is impossible to know what signature the call should | 750 // (this is because it is impossible to know what signature the call should |
861 // have). | 751 // have). |
862 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 752 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
863 options.enableStrictCallChecks = true; | 753 options.enableStrictCallChecks = true; |
864 resetWith(options: options); | 754 resetWith(options: options); |
865 await assertErrorsInCode( | 755 await assertErrorsInCode(''' |
866 ''' | |
867 f(Function f) { | 756 f(Function f) { |
868 return f(); | 757 return f(); |
869 }''', | 758 }''', [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); |
870 [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); | |
871 } | 759 } |
872 | 760 |
873 test_invocationOfNonFunction_localObject() async { | 761 test_invocationOfNonFunction_localObject() async { |
874 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 762 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
875 options.enableStrictCallChecks = true; | 763 options.enableStrictCallChecks = true; |
876 resetWith(options: options); | 764 resetWith(options: options); |
877 await assertErrorsInCode( | 765 await assertErrorsInCode(''' |
878 ''' | |
879 f(Object o) { | 766 f(Object o) { |
880 return o(); | 767 return o(); |
881 }''', | 768 }''', [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); |
882 [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); | |
883 } | 769 } |
884 | 770 |
885 test_invocationOfNonFunction_localVariable() async { | 771 test_invocationOfNonFunction_localVariable() async { |
886 await assertErrorsInCode( | 772 await assertErrorsInCode(r''' |
887 r''' | |
888 f() { | 773 f() { |
889 int x; | 774 int x; |
890 return x(); | 775 return x(); |
891 }''', | 776 }''', [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); |
892 [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); | |
893 } | 777 } |
894 | 778 |
895 test_invocationOfNonFunction_ordinaryInvocation() async { | 779 test_invocationOfNonFunction_ordinaryInvocation() async { |
896 await assertErrorsInCode( | 780 await assertErrorsInCode(r''' |
897 r''' | |
898 class A { | 781 class A { |
899 static int x; | 782 static int x; |
900 } | 783 } |
901 class B { | 784 class B { |
902 m() { | 785 m() { |
903 A.x(); | 786 A.x(); |
904 } | 787 } |
905 }''', | 788 }''', [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); |
906 [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); | |
907 // A call to verify(source) fails as A.x() cannot be resolved. | 789 // A call to verify(source) fails as A.x() cannot be resolved. |
908 } | 790 } |
909 | 791 |
910 test_invocationOfNonFunction_staticInvocation() async { | 792 test_invocationOfNonFunction_staticInvocation() async { |
911 await assertErrorsInCode( | 793 await assertErrorsInCode(r''' |
912 r''' | |
913 class A { | 794 class A { |
914 static int get g => 0; | 795 static int get g => 0; |
915 f() { | 796 f() { |
916 A.g(); | 797 A.g(); |
917 } | 798 } |
918 }''', | 799 }''', [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); |
919 [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); | |
920 // A call to verify(source) fails as g() cannot be resolved. | 800 // A call to verify(source) fails as g() cannot be resolved. |
921 } | 801 } |
922 | 802 |
923 test_invocationOfNonFunction_superExpression() async { | 803 test_invocationOfNonFunction_superExpression() async { |
924 await assertErrorsInCode( | 804 await assertErrorsInCode(r''' |
925 r''' | |
926 class A { | 805 class A { |
927 int get g => 0; | 806 int get g => 0; |
928 } | 807 } |
929 class B extends A { | 808 class B extends A { |
930 m() { | 809 m() { |
931 var v = super.g(); | 810 var v = super.g(); |
932 } | 811 } |
933 }''', | 812 }''', [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); |
934 [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]); | |
935 } | 813 } |
936 | 814 |
937 test_invocationOfNonFunctionExpression_literal() async { | 815 test_invocationOfNonFunctionExpression_literal() async { |
938 await assertErrorsInCode( | 816 await assertErrorsInCode(r''' |
939 r''' | |
940 f() { | 817 f() { |
941 3(5); | 818 3(5); |
942 }''', | 819 }''', [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION]); |
943 [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION]); | |
944 } | 820 } |
945 | 821 |
946 test_nonBoolCondition_conditional() async { | 822 test_nonBoolCondition_conditional() async { |
947 await assertErrorsInCode("f() { return 3 ? 2 : 1; }", | 823 await assertErrorsInCode("f() { return 3 ? 2 : 1; }", |
948 [StaticTypeWarningCode.NON_BOOL_CONDITION]); | 824 [StaticTypeWarningCode.NON_BOOL_CONDITION]); |
949 } | 825 } |
950 | 826 |
951 test_nonBoolCondition_do() async { | 827 test_nonBoolCondition_do() async { |
952 await assertErrorsInCode( | 828 await assertErrorsInCode(r''' |
953 r''' | |
954 f() { | 829 f() { |
955 do {} while (3); | 830 do {} while (3); |
956 }''', | 831 }''', [StaticTypeWarningCode.NON_BOOL_CONDITION]); |
957 [StaticTypeWarningCode.NON_BOOL_CONDITION]); | |
958 } | 832 } |
959 | 833 |
960 test_nonBoolCondition_for() async { | 834 test_nonBoolCondition_for() async { |
961 // https://github.com/dart-lang/sdk/issues/24713 | 835 // https://github.com/dart-lang/sdk/issues/24713 |
962 await assertErrorsInCode( | 836 await assertErrorsInCode(r''' |
963 r''' | |
964 f() { | 837 f() { |
965 for (;3;) {} | 838 for (;3;) {} |
966 }''', | 839 }''', [StaticTypeWarningCode.NON_BOOL_CONDITION]); |
967 [StaticTypeWarningCode.NON_BOOL_CONDITION]); | |
968 } | 840 } |
969 | 841 |
970 test_nonBoolCondition_if() async { | 842 test_nonBoolCondition_if() async { |
971 await assertErrorsInCode( | 843 await assertErrorsInCode(r''' |
972 r''' | |
973 f() { | 844 f() { |
974 if (3) return 2; else return 1; | 845 if (3) return 2; else return 1; |
975 }''', | 846 }''', [StaticTypeWarningCode.NON_BOOL_CONDITION]); |
976 [StaticTypeWarningCode.NON_BOOL_CONDITION]); | |
977 } | 847 } |
978 | 848 |
979 test_nonBoolCondition_while() async { | 849 test_nonBoolCondition_while() async { |
980 await assertErrorsInCode( | 850 await assertErrorsInCode(r''' |
981 r''' | |
982 f() { | 851 f() { |
983 while (3) {} | 852 while (3) {} |
984 }''', | 853 }''', [StaticTypeWarningCode.NON_BOOL_CONDITION]); |
985 [StaticTypeWarningCode.NON_BOOL_CONDITION]); | |
986 } | 854 } |
987 | 855 |
988 test_nonBoolExpression_functionType() async { | 856 test_nonBoolExpression_functionType() async { |
989 await assertErrorsInCode( | 857 await assertErrorsInCode(r''' |
990 r''' | |
991 int makeAssertion() => 1; | 858 int makeAssertion() => 1; |
992 f() { | 859 f() { |
993 assert(makeAssertion); | 860 assert(makeAssertion); |
994 }''', | 861 }''', [StaticTypeWarningCode.NON_BOOL_EXPRESSION]); |
995 [StaticTypeWarningCode.NON_BOOL_EXPRESSION]); | |
996 } | 862 } |
997 | 863 |
998 test_nonBoolExpression_interfaceType() async { | 864 test_nonBoolExpression_interfaceType() async { |
999 await assertErrorsInCode( | 865 await assertErrorsInCode(r''' |
1000 r''' | |
1001 f() { | 866 f() { |
1002 assert(0); | 867 assert(0); |
1003 }''', | 868 }''', [StaticTypeWarningCode.NON_BOOL_EXPRESSION]); |
1004 [StaticTypeWarningCode.NON_BOOL_EXPRESSION]); | |
1005 } | 869 } |
1006 | 870 |
1007 test_nonBoolNegationExpression() async { | 871 test_nonBoolNegationExpression() async { |
1008 await assertErrorsInCode( | 872 await assertErrorsInCode(r''' |
1009 r''' | |
1010 f() { | 873 f() { |
1011 !42; | 874 !42; |
1012 }''', | 875 }''', [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]); |
1013 [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]); | |
1014 } | 876 } |
1015 | 877 |
1016 test_nonBoolOperand_and_left() async { | 878 test_nonBoolOperand_and_left() async { |
1017 await assertErrorsInCode( | 879 await assertErrorsInCode(r''' |
1018 r''' | |
1019 bool f(int left, bool right) { | 880 bool f(int left, bool right) { |
1020 return left && right; | 881 return left && right; |
1021 }''', | 882 }''', [StaticTypeWarningCode.NON_BOOL_OPERAND]); |
1022 [StaticTypeWarningCode.NON_BOOL_OPERAND]); | |
1023 } | 883 } |
1024 | 884 |
1025 test_nonBoolOperand_and_right() async { | 885 test_nonBoolOperand_and_right() async { |
1026 await assertErrorsInCode( | 886 await assertErrorsInCode(r''' |
1027 r''' | |
1028 bool f(bool left, String right) { | 887 bool f(bool left, String right) { |
1029 return left && right; | 888 return left && right; |
1030 }''', | 889 }''', [StaticTypeWarningCode.NON_BOOL_OPERAND]); |
1031 [StaticTypeWarningCode.NON_BOOL_OPERAND]); | |
1032 } | 890 } |
1033 | 891 |
1034 test_nonBoolOperand_or_left() async { | 892 test_nonBoolOperand_or_left() async { |
1035 await assertErrorsInCode( | 893 await assertErrorsInCode(r''' |
1036 r''' | |
1037 bool f(List<int> left, bool right) { | 894 bool f(List<int> left, bool right) { |
1038 return left || right; | 895 return left || right; |
1039 }''', | 896 }''', [StaticTypeWarningCode.NON_BOOL_OPERAND]); |
1040 [StaticTypeWarningCode.NON_BOOL_OPERAND]); | |
1041 } | 897 } |
1042 | 898 |
1043 test_nonBoolOperand_or_right() async { | 899 test_nonBoolOperand_or_right() async { |
1044 await assertErrorsInCode( | 900 await assertErrorsInCode(r''' |
1045 r''' | |
1046 bool f(bool left, double right) { | 901 bool f(bool left, double right) { |
1047 return left || right; | 902 return left || right; |
1048 }''', | 903 }''', [StaticTypeWarningCode.NON_BOOL_OPERAND]); |
1049 [StaticTypeWarningCode.NON_BOOL_OPERAND]); | |
1050 } | 904 } |
1051 | 905 |
1052 test_nonTypeAsTypeArgument_notAType() async { | 906 test_nonTypeAsTypeArgument_notAType() async { |
1053 await assertErrorsInCode( | 907 await assertErrorsInCode(r''' |
1054 r''' | |
1055 int A; | 908 int A; |
1056 class B<E> {} | 909 class B<E> {} |
1057 f(B<A> b) {}''', | 910 f(B<A> b) {}''', [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]); |
1058 [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]); | |
1059 } | 911 } |
1060 | 912 |
1061 test_nonTypeAsTypeArgument_undefinedIdentifier() async { | 913 test_nonTypeAsTypeArgument_undefinedIdentifier() async { |
1062 await assertErrorsInCode( | 914 await assertErrorsInCode(r''' |
1063 r''' | |
1064 class B<E> {} | 915 class B<E> {} |
1065 f(B<A> b) {}''', | 916 f(B<A> b) {}''', [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]); |
1066 [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]); | |
1067 } | 917 } |
1068 | 918 |
1069 test_returnOfInvalidType_async_future_int_mismatches_future_string() async { | 919 test_returnOfInvalidType_async_future_int_mismatches_future_string() async { |
1070 await assertErrorsInCode( | 920 await assertErrorsInCode(''' |
1071 ''' | |
1072 import 'dart:async'; | 921 import 'dart:async'; |
1073 Future<String> f() async { | 922 Future<String> f() async { |
1074 return 5; | 923 return 5; |
1075 } | 924 } |
1076 ''', | 925 ''', [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1077 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | |
1078 } | 926 } |
1079 | 927 |
1080 test_returnOfInvalidType_async_future_int_mismatches_int() async { | 928 test_returnOfInvalidType_async_future_int_mismatches_int() async { |
1081 await assertErrorsInCode( | 929 await assertErrorsInCode(''' |
1082 ''' | |
1083 int f() async { | 930 int f() async { |
1084 return 5; | 931 return 5; |
1085 } | 932 } |
1086 ''', | 933 ''', [ |
1087 [ | 934 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, |
1088 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, | 935 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE |
1089 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE | 936 ]); |
1090 ]); | |
1091 } | 937 } |
1092 | 938 |
1093 test_returnOfInvalidType_expressionFunctionBody_function() async { | 939 test_returnOfInvalidType_expressionFunctionBody_function() async { |
1094 await assertErrorsInCode( | 940 await assertErrorsInCode( |
1095 "int f() => '0';", [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | 941 "int f() => '0';", [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1096 } | 942 } |
1097 | 943 |
1098 test_returnOfInvalidType_expressionFunctionBody_getter() async { | 944 test_returnOfInvalidType_expressionFunctionBody_getter() async { |
1099 await assertErrorsInCode( | 945 await assertErrorsInCode( |
1100 "int get g => '0';", [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | 946 "int get g => '0';", [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1101 } | 947 } |
1102 | 948 |
1103 test_returnOfInvalidType_expressionFunctionBody_localFunction() async { | 949 test_returnOfInvalidType_expressionFunctionBody_localFunction() async { |
1104 await assertErrorsInCode( | 950 await assertErrorsInCode(r''' |
1105 r''' | |
1106 class A { | 951 class A { |
1107 String m() { | 952 String m() { |
1108 int f() => '0'; | 953 int f() => '0'; |
1109 return '0'; | 954 return '0'; |
1110 } | 955 } |
1111 }''', | 956 }''', [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1112 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | |
1113 } | 957 } |
1114 | 958 |
1115 test_returnOfInvalidType_expressionFunctionBody_method() async { | 959 test_returnOfInvalidType_expressionFunctionBody_method() async { |
1116 await assertErrorsInCode( | 960 await assertErrorsInCode(r''' |
1117 r''' | |
1118 class A { | 961 class A { |
1119 int f() => '0'; | 962 int f() => '0'; |
1120 }''', | 963 }''', [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1121 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | |
1122 } | 964 } |
1123 | 965 |
1124 test_returnOfInvalidType_function() async { | 966 test_returnOfInvalidType_function() async { |
1125 await assertErrorsInCode("int f() { return '0'; }", | 967 await assertErrorsInCode("int f() { return '0'; }", |
1126 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | 968 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1127 } | 969 } |
1128 | 970 |
1129 test_returnOfInvalidType_getter() async { | 971 test_returnOfInvalidType_getter() async { |
1130 await assertErrorsInCode("int get g { return '0'; }", | 972 await assertErrorsInCode("int get g { return '0'; }", |
1131 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | 973 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1132 } | 974 } |
1133 | 975 |
1134 test_returnOfInvalidType_localFunction() async { | 976 test_returnOfInvalidType_localFunction() async { |
1135 await assertErrorsInCode( | 977 await assertErrorsInCode(r''' |
1136 r''' | |
1137 class A { | 978 class A { |
1138 String m() { | 979 String m() { |
1139 int f() { return '0'; } | 980 int f() { return '0'; } |
1140 return '0'; | 981 return '0'; |
1141 } | 982 } |
1142 }''', | 983 }''', [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1143 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | |
1144 } | 984 } |
1145 | 985 |
1146 test_returnOfInvalidType_method() async { | 986 test_returnOfInvalidType_method() async { |
1147 await assertErrorsInCode( | 987 await assertErrorsInCode(r''' |
1148 r''' | |
1149 class A { | 988 class A { |
1150 int f() { return '0'; } | 989 int f() { return '0'; } |
1151 }''', | 990 }''', [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1152 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | |
1153 } | 991 } |
1154 | 992 |
1155 test_returnOfInvalidType_not_issued_for_expressionFunctionBody_void() async { | 993 test_returnOfInvalidType_not_issued_for_expressionFunctionBody_void() async { |
1156 await assertNoErrorsInCode("void f() => 42;"); | 994 await assertNoErrorsInCode("void f() => 42;"); |
1157 } | 995 } |
1158 | 996 |
1159 test_returnOfInvalidType_not_issued_for_valid_generic_return() async { | 997 test_returnOfInvalidType_not_issued_for_valid_generic_return() async { |
1160 await assertNoErrorsInCode(r''' | 998 await assertNoErrorsInCode(r''' |
1161 abstract class F<T, U> { | 999 abstract class F<T, U> { |
1162 U get value; | 1000 U get value; |
1163 } | 1001 } |
1164 | 1002 |
1165 abstract class G<T> { | 1003 abstract class G<T> { |
1166 T test(F<int, T> arg) => arg.value; | 1004 T test(F<int, T> arg) => arg.value; |
1167 } | 1005 } |
1168 | 1006 |
1169 abstract class H<S> { | 1007 abstract class H<S> { |
1170 S test(F<int, S> arg) => arg.value; | 1008 S test(F<int, S> arg) => arg.value; |
1171 } | 1009 } |
1172 | 1010 |
1173 void main() { }'''); | 1011 void main() { }'''); |
1174 } | 1012 } |
1175 | 1013 |
1176 test_returnOfInvalidType_void() async { | 1014 test_returnOfInvalidType_void() async { |
1177 await assertErrorsInCode("void f() { return 42; }", | 1015 await assertErrorsInCode("void f() { return 42; }", |
1178 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); | 1016 [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]); |
1179 } | 1017 } |
1180 | 1018 |
1181 test_typeArgumentNotMatchingBounds_classTypeAlias() async { | 1019 test_typeArgumentNotMatchingBounds_classTypeAlias() async { |
1182 await assertErrorsInCode( | 1020 await assertErrorsInCode(r''' |
1183 r''' | |
1184 class A {} | 1021 class A {} |
1185 class B {} | 1022 class B {} |
1186 class C {} | 1023 class C {} |
1187 class G<E extends A> {} | 1024 class G<E extends A> {} |
1188 class D = G<B> with C; | 1025 class D = G<B> with C; |
1189 ''', | 1026 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1190 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1191 } | 1027 } |
1192 | 1028 |
1193 test_typeArgumentNotMatchingBounds_extends() async { | 1029 test_typeArgumentNotMatchingBounds_extends() async { |
1194 await assertErrorsInCode( | 1030 await assertErrorsInCode(r''' |
1195 r''' | |
1196 class A {} | 1031 class A {} |
1197 class B {} | 1032 class B {} |
1198 class G<E extends A> {} | 1033 class G<E extends A> {} |
1199 class C extends G<B>{} | 1034 class C extends G<B>{} |
1200 ''', | 1035 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1201 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1202 } | 1036 } |
1203 | 1037 |
1204 test_typeArgumentNotMatchingBounds_extends_regressionInIssue18468Fix() async { | 1038 test_typeArgumentNotMatchingBounds_extends_regressionInIssue18468Fix() async { |
1205 // https://code.google.com/p/dart/issues/detail?id=18628 | 1039 // https://code.google.com/p/dart/issues/detail?id=18628 |
1206 await assertErrorsInCode( | 1040 await assertErrorsInCode(r''' |
1207 r''' | |
1208 class X<T extends Type> {} | 1041 class X<T extends Type> {} |
1209 class Y<U> extends X<U> {} | 1042 class Y<U> extends X<U> {} |
1210 ''', | 1043 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1211 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1212 } | 1044 } |
1213 | 1045 |
1214 test_typeArgumentNotMatchingBounds_fieldFormalParameter() async { | 1046 test_typeArgumentNotMatchingBounds_fieldFormalParameter() async { |
1215 await assertErrorsInCode( | 1047 await assertErrorsInCode(r''' |
1216 r''' | |
1217 class A {} | 1048 class A {} |
1218 class B {} | 1049 class B {} |
1219 class G<E extends A> {} | 1050 class G<E extends A> {} |
1220 class C { | 1051 class C { |
1221 var f; | 1052 var f; |
1222 C(G<B> this.f) {} | 1053 C(G<B> this.f) {} |
1223 }''', | 1054 }''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1224 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1225 } | 1055 } |
1226 | 1056 |
1227 test_typeArgumentNotMatchingBounds_functionReturnType() async { | 1057 test_typeArgumentNotMatchingBounds_functionReturnType() async { |
1228 await assertErrorsInCode( | 1058 await assertErrorsInCode(r''' |
1229 r''' | |
1230 class A {} | 1059 class A {} |
1231 class B {} | 1060 class B {} |
1232 class G<E extends A> {} | 1061 class G<E extends A> {} |
1233 G<B> f() { return null; } | 1062 G<B> f() { return null; } |
1234 ''', | 1063 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1235 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1236 } | 1064 } |
1237 | 1065 |
1238 test_typeArgumentNotMatchingBounds_functionTypeAlias() async { | 1066 test_typeArgumentNotMatchingBounds_functionTypeAlias() async { |
1239 await assertErrorsInCode( | 1067 await assertErrorsInCode(r''' |
1240 r''' | |
1241 class A {} | 1068 class A {} |
1242 class B {} | 1069 class B {} |
1243 class G<E extends A> {} | 1070 class G<E extends A> {} |
1244 typedef G<B> f(); | 1071 typedef G<B> f(); |
1245 ''', | 1072 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1246 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1247 } | 1073 } |
1248 | 1074 |
1249 test_typeArgumentNotMatchingBounds_functionTypedFormalParameter() async { | 1075 test_typeArgumentNotMatchingBounds_functionTypedFormalParameter() async { |
1250 await assertErrorsInCode( | 1076 await assertErrorsInCode(r''' |
1251 r''' | |
1252 class A {} | 1077 class A {} |
1253 class B {} | 1078 class B {} |
1254 class G<E extends A> {} | 1079 class G<E extends A> {} |
1255 f(G<B> h()) {} | 1080 f(G<B> h()) {} |
1256 ''', | 1081 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1257 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1258 } | 1082 } |
1259 | 1083 |
1260 test_typeArgumentNotMatchingBounds_implements() async { | 1084 test_typeArgumentNotMatchingBounds_implements() async { |
1261 await assertErrorsInCode( | 1085 await assertErrorsInCode(r''' |
1262 r''' | |
1263 class A {} | 1086 class A {} |
1264 class B {} | 1087 class B {} |
1265 class G<E extends A> {} | 1088 class G<E extends A> {} |
1266 class C implements G<B>{} | 1089 class C implements G<B>{} |
1267 ''', | 1090 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1268 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1269 } | 1091 } |
1270 | 1092 |
1271 test_typeArgumentNotMatchingBounds_is() async { | 1093 test_typeArgumentNotMatchingBounds_is() async { |
1272 await assertErrorsInCode( | 1094 await assertErrorsInCode(r''' |
1273 r''' | |
1274 class A {} | 1095 class A {} |
1275 class B {} | 1096 class B {} |
1276 class G<E extends A> {} | 1097 class G<E extends A> {} |
1277 var b = 1 is G<B>; | 1098 var b = 1 is G<B>; |
1278 ''', | 1099 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1279 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1280 } | 1100 } |
1281 | 1101 |
1282 test_typeArgumentNotMatchingBounds_methodInvocation_localFunction() async { | 1102 test_typeArgumentNotMatchingBounds_methodInvocation_localFunction() async { |
1283 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 1103 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
1284 await assertErrorsInCode( | 1104 await assertErrorsInCode(r''' |
1285 r''' | |
1286 class Point<T extends num> { | 1105 class Point<T extends num> { |
1287 Point(T x, T y); | 1106 Point(T x, T y); |
1288 } | 1107 } |
1289 | 1108 |
1290 main() { | 1109 main() { |
1291 Point/*<T>*/ f/*<T extends num>*/(num/*=T*/ x, num/*=T*/ y) { | 1110 Point/*<T>*/ f/*<T extends num>*/(num/*=T*/ x, num/*=T*/ y) { |
1292 return new Point/*<T>*/(x, y); | 1111 return new Point/*<T>*/(x, y); |
1293 } | 1112 } |
1294 print(f/*<String>*/('hello', 'world')); | 1113 print(f/*<String>*/('hello', 'world')); |
1295 } | 1114 } |
1296 ''', | 1115 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1297 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1298 } | 1116 } |
1299 | 1117 |
1300 test_typeArgumentNotMatchingBounds_methodInvocation_method() async { | 1118 test_typeArgumentNotMatchingBounds_methodInvocation_method() async { |
1301 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 1119 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
1302 await assertErrorsInCode( | 1120 await assertErrorsInCode(r''' |
1303 r''' | |
1304 class Point<T extends num> { | 1121 class Point<T extends num> { |
1305 Point(T x, T y); | 1122 Point(T x, T y); |
1306 } | 1123 } |
1307 | 1124 |
1308 class PointFactory { | 1125 class PointFactory { |
1309 Point/*<T>*/ point/*<T extends num>*/(num/*=T*/ x, num/*=T*/ y) { | 1126 Point/*<T>*/ point/*<T extends num>*/(num/*=T*/ x, num/*=T*/ y) { |
1310 return new Point/*<T>*/(x, y); | 1127 return new Point/*<T>*/(x, y); |
1311 } | 1128 } |
1312 } | 1129 } |
1313 | 1130 |
1314 f(PointFactory factory) { | 1131 f(PointFactory factory) { |
1315 print(factory.point/*<String>*/('hello', 'world')); | 1132 print(factory.point/*<String>*/('hello', 'world')); |
1316 } | 1133 } |
1317 ''', | 1134 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1318 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1319 } | 1135 } |
1320 | 1136 |
1321 test_typeArgumentNotMatchingBounds_methodInvocation_topLevelFunction() async { | 1137 test_typeArgumentNotMatchingBounds_methodInvocation_topLevelFunction() async { |
1322 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 1138 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
1323 await assertErrorsInCode( | 1139 await assertErrorsInCode(r''' |
1324 r''' | |
1325 class Point<T extends num> { | 1140 class Point<T extends num> { |
1326 Point(T x, T y); | 1141 Point(T x, T y); |
1327 } | 1142 } |
1328 | 1143 |
1329 Point/*<T>*/ f/*<T extends num>*/(num/*=T*/ x, num/*=T*/ y) { | 1144 Point/*<T>*/ f/*<T extends num>*/(num/*=T*/ x, num/*=T*/ y) { |
1330 return new Point/*<T>*/(x, y); | 1145 return new Point/*<T>*/(x, y); |
1331 } | 1146 } |
1332 | 1147 |
1333 main() { | 1148 main() { |
1334 print(f/*<String>*/('hello', 'world')); | 1149 print(f/*<String>*/('hello', 'world')); |
1335 } | 1150 } |
1336 ''', | 1151 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1337 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1338 } | 1152 } |
1339 | 1153 |
1340 test_typeArgumentNotMatchingBounds_methodReturnType() async { | 1154 test_typeArgumentNotMatchingBounds_methodReturnType() async { |
1341 await assertErrorsInCode( | 1155 await assertErrorsInCode(r''' |
1342 r''' | |
1343 class A {} | 1156 class A {} |
1344 class B {} | 1157 class B {} |
1345 class G<E extends A> {} | 1158 class G<E extends A> {} |
1346 class C { | 1159 class C { |
1347 G<B> m() { return null; } | 1160 G<B> m() { return null; } |
1348 }''', | 1161 }''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1349 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1350 } | 1162 } |
1351 | 1163 |
1352 test_typeArgumentNotMatchingBounds_new() async { | 1164 test_typeArgumentNotMatchingBounds_new() async { |
1353 await assertErrorsInCode( | 1165 await assertErrorsInCode(r''' |
1354 r''' | |
1355 class A {} | 1166 class A {} |
1356 class B {} | 1167 class B {} |
1357 class G<E extends A> {} | 1168 class G<E extends A> {} |
1358 f() { return new G<B>(); } | 1169 f() { return new G<B>(); } |
1359 ''', | 1170 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1360 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1361 } | 1171 } |
1362 | 1172 |
1363 test_typeArgumentNotMatchingBounds_new_superTypeOfUpperBound() async { | 1173 test_typeArgumentNotMatchingBounds_new_superTypeOfUpperBound() async { |
1364 await assertErrorsInCode( | 1174 await assertErrorsInCode(r''' |
1365 r''' | |
1366 class A {} | 1175 class A {} |
1367 class B extends A {} | 1176 class B extends A {} |
1368 class C extends B {} | 1177 class C extends B {} |
1369 class G<E extends B> {} | 1178 class G<E extends B> {} |
1370 f() { return new G<A>(); } | 1179 f() { return new G<A>(); } |
1371 ''', | 1180 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1372 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1373 } | 1181 } |
1374 | 1182 |
1375 test_typeArgumentNotMatchingBounds_parameter() async { | 1183 test_typeArgumentNotMatchingBounds_parameter() async { |
1376 await assertErrorsInCode( | 1184 await assertErrorsInCode(r''' |
1377 r''' | |
1378 class A {} | 1185 class A {} |
1379 class B {} | 1186 class B {} |
1380 class G<E extends A> {} | 1187 class G<E extends A> {} |
1381 f(G<B> g) {} | 1188 f(G<B> g) {} |
1382 ''', | 1189 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1383 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1384 } | 1190 } |
1385 | 1191 |
1386 test_typeArgumentNotMatchingBounds_redirectingConstructor() async { | 1192 test_typeArgumentNotMatchingBounds_redirectingConstructor() async { |
1387 await assertErrorsInCode( | 1193 await assertErrorsInCode(r''' |
1388 r''' | |
1389 class A {} | 1194 class A {} |
1390 class B {} | 1195 class B {} |
1391 class X<T extends A> { | 1196 class X<T extends A> { |
1392 X(int x, int y) {} | 1197 X(int x, int y) {} |
1393 factory X.name(int x, int y) = X<B>; | 1198 factory X.name(int x, int y) = X<B>; |
1394 }''', | 1199 }''', [ |
1395 [ | 1200 StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, |
1396 StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, | 1201 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE |
1397 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE | 1202 ]); |
1398 ]); | |
1399 } | 1203 } |
1400 | 1204 |
1401 test_typeArgumentNotMatchingBounds_typeArgumentList() async { | 1205 test_typeArgumentNotMatchingBounds_typeArgumentList() async { |
1402 await assertErrorsInCode( | 1206 await assertErrorsInCode(r''' |
1403 r''' | |
1404 class A {} | 1207 class A {} |
1405 class B {} | 1208 class B {} |
1406 class C<E> {} | 1209 class C<E> {} |
1407 class D<E extends A> {} | 1210 class D<E extends A> {} |
1408 C<D<B>> Var; | 1211 C<D<B>> Var; |
1409 ''', | 1212 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1410 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1411 } | 1213 } |
1412 | 1214 |
1413 test_typeArgumentNotMatchingBounds_typeParameter() async { | 1215 test_typeArgumentNotMatchingBounds_typeParameter() async { |
1414 await assertErrorsInCode( | 1216 await assertErrorsInCode(r''' |
1415 r''' | |
1416 class A {} | 1217 class A {} |
1417 class B {} | 1218 class B {} |
1418 class C {} | 1219 class C {} |
1419 class G<E extends A> {} | 1220 class G<E extends A> {} |
1420 class D<F extends G<B>> {} | 1221 class D<F extends G<B>> {} |
1421 ''', | 1222 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1422 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1423 } | 1223 } |
1424 | 1224 |
1425 test_typeArgumentNotMatchingBounds_variableDeclaration() async { | 1225 test_typeArgumentNotMatchingBounds_variableDeclaration() async { |
1426 await assertErrorsInCode( | 1226 await assertErrorsInCode(r''' |
1427 r''' | |
1428 class A {} | 1227 class A {} |
1429 class B {} | 1228 class B {} |
1430 class G<E extends A> {} | 1229 class G<E extends A> {} |
1431 G<B> g; | 1230 G<B> g; |
1432 ''', | 1231 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1433 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1434 } | 1232 } |
1435 | 1233 |
1436 test_typeArgumentNotMatchingBounds_with() async { | 1234 test_typeArgumentNotMatchingBounds_with() async { |
1437 await assertErrorsInCode( | 1235 await assertErrorsInCode(r''' |
1438 r''' | |
1439 class A {} | 1236 class A {} |
1440 class B {} | 1237 class B {} |
1441 class G<E extends A> {} | 1238 class G<E extends A> {} |
1442 class C extends Object with G<B>{} | 1239 class C extends Object with G<B>{} |
1443 ''', | 1240 ''', [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
1444 [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | |
1445 } | 1241 } |
1446 | 1242 |
1447 test_typeParameterSupertypeOfItsBound() async { | 1243 test_typeParameterSupertypeOfItsBound() async { |
1448 await assertErrorsInCode( | 1244 await assertErrorsInCode(r''' |
1449 r''' | |
1450 class A<T extends T> { | 1245 class A<T extends T> { |
1451 } | 1246 } |
1452 ''', | 1247 ''', [StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND]); |
1453 [StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND]); | |
1454 } | 1248 } |
1455 | 1249 |
1456 test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_mutated() asyn
c { | 1250 test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_mutated() asyn
c { |
1457 await assertErrorsInUnverifiedCode( | 1251 await assertErrorsInUnverifiedCode(r''' |
1458 r''' | |
1459 callMe(f()) { f(); } | 1252 callMe(f()) { f(); } |
1460 main(Object p) { | 1253 main(Object p) { |
1461 (p is String) && callMe(() { p.length; }); | 1254 (p is String) && callMe(() { p.length; }); |
1462 p = 0; | 1255 p = 0; |
1463 }''', | 1256 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1464 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1465 } | 1257 } |
1466 | 1258 |
1467 test_typePromotion_booleanAnd_useInRight_mutatedInLeft() async { | 1259 test_typePromotion_booleanAnd_useInRight_mutatedInLeft() async { |
1468 await assertErrorsInUnverifiedCode( | 1260 await assertErrorsInUnverifiedCode(r''' |
1469 r''' | |
1470 main(Object p) { | 1261 main(Object p) { |
1471 ((p is String) && ((p = 42) == 42)) && p.length != 0; | 1262 ((p is String) && ((p = 42) == 42)) && p.length != 0; |
1472 }''', | 1263 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1473 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1474 } | 1264 } |
1475 | 1265 |
1476 test_typePromotion_booleanAnd_useInRight_mutatedInRight() async { | 1266 test_typePromotion_booleanAnd_useInRight_mutatedInRight() async { |
1477 await assertErrorsInUnverifiedCode( | 1267 await assertErrorsInUnverifiedCode(r''' |
1478 r''' | |
1479 main(Object p) { | 1268 main(Object p) { |
1480 (p is String) && (((p = 42) == 42) && p.length != 0); | 1269 (p is String) && (((p = 42) == 42) && p.length != 0); |
1481 }''', | 1270 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1482 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1483 } | 1271 } |
1484 | 1272 |
1485 test_typePromotion_conditional_useInThen_accessedInClosure_hasAssignment_after
() async { | 1273 test_typePromotion_conditional_useInThen_accessedInClosure_hasAssignment_after
() async { |
1486 await assertErrorsInUnverifiedCode( | 1274 await assertErrorsInUnverifiedCode(r''' |
1487 r''' | |
1488 callMe(f()) { f(); } | 1275 callMe(f()) { f(); } |
1489 main(Object p) { | 1276 main(Object p) { |
1490 p is String ? callMe(() { p.length; }) : 0; | 1277 p is String ? callMe(() { p.length; }) : 0; |
1491 p = 42; | 1278 p = 42; |
1492 }''', | 1279 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1493 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1494 } | 1280 } |
1495 | 1281 |
1496 test_typePromotion_conditional_useInThen_accessedInClosure_hasAssignment_befor
e() async { | 1282 test_typePromotion_conditional_useInThen_accessedInClosure_hasAssignment_befor
e() async { |
1497 await assertErrorsInUnverifiedCode( | 1283 await assertErrorsInUnverifiedCode(r''' |
1498 r''' | |
1499 callMe(f()) { f(); } | 1284 callMe(f()) { f(); } |
1500 main(Object p) { | 1285 main(Object p) { |
1501 p = 42; | 1286 p = 42; |
1502 p is String ? callMe(() { p.length; }) : 0; | 1287 p is String ? callMe(() { p.length; }) : 0; |
1503 }''', | 1288 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1504 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1505 } | 1289 } |
1506 | 1290 |
1507 test_typePromotion_conditional_useInThen_hasAssignment() async { | 1291 test_typePromotion_conditional_useInThen_hasAssignment() async { |
1508 await assertErrorsInUnverifiedCode( | 1292 await assertErrorsInUnverifiedCode(r''' |
1509 r''' | |
1510 main(Object p) { | 1293 main(Object p) { |
1511 p is String ? (p.length + (p = 42)) : 0; | 1294 p is String ? (p.length + (p = 42)) : 0; |
1512 }''', | 1295 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1513 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1514 } | 1296 } |
1515 | 1297 |
1516 test_typePromotion_if_accessedInClosure_hasAssignment() async { | 1298 test_typePromotion_if_accessedInClosure_hasAssignment() async { |
1517 await assertErrorsInUnverifiedCode( | 1299 await assertErrorsInUnverifiedCode(r''' |
1518 r''' | |
1519 callMe(f()) { f(); } | 1300 callMe(f()) { f(); } |
1520 main(Object p) { | 1301 main(Object p) { |
1521 if (p is String) { | 1302 if (p is String) { |
1522 callMe(() { | 1303 callMe(() { |
1523 p.length; | 1304 p.length; |
1524 }); | 1305 }); |
1525 } | 1306 } |
1526 p = 0; | 1307 p = 0; |
1527 }''', | 1308 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1528 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1529 } | 1309 } |
1530 | 1310 |
1531 test_typePromotion_if_and_right_hasAssignment() async { | 1311 test_typePromotion_if_and_right_hasAssignment() async { |
1532 await assertErrorsInUnverifiedCode( | 1312 await assertErrorsInUnverifiedCode(r''' |
1533 r''' | |
1534 main(Object p) { | 1313 main(Object p) { |
1535 if (p is String && (p = null) == null) { | 1314 if (p is String && (p = null) == null) { |
1536 p.length; | 1315 p.length; |
1537 } | 1316 } |
1538 }''', | 1317 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1539 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1540 } | 1318 } |
1541 | 1319 |
1542 test_typePromotion_if_extends_notMoreSpecific_dynamic() async { | 1320 test_typePromotion_if_extends_notMoreSpecific_dynamic() async { |
1543 await assertErrorsInUnverifiedCode( | 1321 await assertErrorsInUnverifiedCode(r''' |
1544 r''' | |
1545 class V {} | 1322 class V {} |
1546 class A<T> {} | 1323 class A<T> {} |
1547 class B<S> extends A<S> { | 1324 class B<S> extends A<S> { |
1548 var b; | 1325 var b; |
1549 } | 1326 } |
1550 | 1327 |
1551 main(A<V> p) { | 1328 main(A<V> p) { |
1552 if (p is B) { | 1329 if (p is B) { |
1553 p.b; | 1330 p.b; |
1554 } | 1331 } |
1555 }''', | 1332 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1556 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1557 } | 1333 } |
1558 | 1334 |
1559 test_typePromotion_if_extends_notMoreSpecific_notMoreSpecificTypeArg() async { | 1335 test_typePromotion_if_extends_notMoreSpecific_notMoreSpecificTypeArg() async { |
1560 await assertErrorsInUnverifiedCode( | 1336 await assertErrorsInUnverifiedCode(r''' |
1561 r''' | |
1562 class V {} | 1337 class V {} |
1563 class A<T> {} | 1338 class A<T> {} |
1564 class B<S> extends A<S> { | 1339 class B<S> extends A<S> { |
1565 var b; | 1340 var b; |
1566 } | 1341 } |
1567 | 1342 |
1568 main(A<V> p) { | 1343 main(A<V> p) { |
1569 if (p is B<int>) { | 1344 if (p is B<int>) { |
1570 p.b; | 1345 p.b; |
1571 } | 1346 } |
1572 }''', | 1347 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1573 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1574 } | 1348 } |
1575 | 1349 |
1576 test_typePromotion_if_hasAssignment_after() async { | 1350 test_typePromotion_if_hasAssignment_after() async { |
1577 await assertErrorsInUnverifiedCode( | 1351 await assertErrorsInUnverifiedCode(r''' |
1578 r''' | |
1579 main(Object p) { | 1352 main(Object p) { |
1580 if (p is String) { | 1353 if (p is String) { |
1581 p.length; | 1354 p.length; |
1582 p = 0; | 1355 p = 0; |
1583 } | 1356 } |
1584 }''', | 1357 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1585 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1586 } | 1358 } |
1587 | 1359 |
1588 test_typePromotion_if_hasAssignment_before() async { | 1360 test_typePromotion_if_hasAssignment_before() async { |
1589 await assertErrorsInUnverifiedCode( | 1361 await assertErrorsInUnverifiedCode(r''' |
1590 r''' | |
1591 main(Object p) { | 1362 main(Object p) { |
1592 if (p is String) { | 1363 if (p is String) { |
1593 p = 0; | 1364 p = 0; |
1594 p.length; | 1365 p.length; |
1595 } | 1366 } |
1596 }''', | 1367 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1597 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1598 } | 1368 } |
1599 | 1369 |
1600 test_typePromotion_if_hasAssignment_inClosure_anonymous_after() async { | 1370 test_typePromotion_if_hasAssignment_inClosure_anonymous_after() async { |
1601 await assertErrorsInUnverifiedCode( | 1371 await assertErrorsInUnverifiedCode(r''' |
1602 r''' | |
1603 main(Object p) { | 1372 main(Object p) { |
1604 if (p is String) { | 1373 if (p is String) { |
1605 p.length; | 1374 p.length; |
1606 } | 1375 } |
1607 () {p = 0;}; | 1376 () {p = 0;}; |
1608 }''', | 1377 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1609 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1610 } | 1378 } |
1611 | 1379 |
1612 test_typePromotion_if_hasAssignment_inClosure_anonymous_before() async { | 1380 test_typePromotion_if_hasAssignment_inClosure_anonymous_before() async { |
1613 await assertErrorsInUnverifiedCode( | 1381 await assertErrorsInUnverifiedCode(r''' |
1614 r''' | |
1615 main(Object p) { | 1382 main(Object p) { |
1616 () {p = 0;}; | 1383 () {p = 0;}; |
1617 if (p is String) { | 1384 if (p is String) { |
1618 p.length; | 1385 p.length; |
1619 } | 1386 } |
1620 }''', | 1387 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1621 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1622 } | 1388 } |
1623 | 1389 |
1624 test_typePromotion_if_hasAssignment_inClosure_function_after() async { | 1390 test_typePromotion_if_hasAssignment_inClosure_function_after() async { |
1625 await assertErrorsInUnverifiedCode( | 1391 await assertErrorsInUnverifiedCode(r''' |
1626 r''' | |
1627 main(Object p) { | 1392 main(Object p) { |
1628 if (p is String) { | 1393 if (p is String) { |
1629 p.length; | 1394 p.length; |
1630 } | 1395 } |
1631 f() {p = 0;}; | 1396 f() {p = 0;}; |
1632 }''', | 1397 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1633 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1634 } | 1398 } |
1635 | 1399 |
1636 test_typePromotion_if_hasAssignment_inClosure_function_before() async { | 1400 test_typePromotion_if_hasAssignment_inClosure_function_before() async { |
1637 await assertErrorsInUnverifiedCode( | 1401 await assertErrorsInUnverifiedCode(r''' |
1638 r''' | |
1639 main(Object p) { | 1402 main(Object p) { |
1640 f() {p = 0;}; | 1403 f() {p = 0;}; |
1641 if (p is String) { | 1404 if (p is String) { |
1642 p.length; | 1405 p.length; |
1643 } | 1406 } |
1644 }''', | 1407 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1645 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1646 } | 1408 } |
1647 | 1409 |
1648 test_typePromotion_if_implements_notMoreSpecific_dynamic() async { | 1410 test_typePromotion_if_implements_notMoreSpecific_dynamic() async { |
1649 await assertErrorsInUnverifiedCode( | 1411 await assertErrorsInUnverifiedCode(r''' |
1650 r''' | |
1651 class V {} | 1412 class V {} |
1652 class A<T> {} | 1413 class A<T> {} |
1653 class B<S> implements A<S> { | 1414 class B<S> implements A<S> { |
1654 var b; | 1415 var b; |
1655 } | 1416 } |
1656 | 1417 |
1657 main(A<V> p) { | 1418 main(A<V> p) { |
1658 if (p is B) { | 1419 if (p is B) { |
1659 p.b; | 1420 p.b; |
1660 } | 1421 } |
1661 }''', | 1422 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1662 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1663 } | 1423 } |
1664 | 1424 |
1665 test_typePromotion_if_with_notMoreSpecific_dynamic() async { | 1425 test_typePromotion_if_with_notMoreSpecific_dynamic() async { |
1666 await assertErrorsInUnverifiedCode( | 1426 await assertErrorsInUnverifiedCode(r''' |
1667 r''' | |
1668 class V {} | 1427 class V {} |
1669 class A<T> {} | 1428 class A<T> {} |
1670 class B<S> extends Object with A<S> { | 1429 class B<S> extends Object with A<S> { |
1671 var b; | 1430 var b; |
1672 } | 1431 } |
1673 | 1432 |
1674 main(A<V> p) { | 1433 main(A<V> p) { |
1675 if (p is B) { | 1434 if (p is B) { |
1676 p.b; | 1435 p.b; |
1677 } | 1436 } |
1678 }''', | 1437 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1679 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1680 } | 1438 } |
1681 | 1439 |
1682 test_undefinedFunction() async { | 1440 test_undefinedFunction() async { |
1683 await assertErrorsInCode( | 1441 await assertErrorsInCode(r''' |
1684 r''' | |
1685 void f() { | 1442 void f() { |
1686 g(); | 1443 g(); |
1687 }''', | 1444 }''', [StaticTypeWarningCode.UNDEFINED_FUNCTION]); |
1688 [StaticTypeWarningCode.UNDEFINED_FUNCTION]); | |
1689 } | 1445 } |
1690 | 1446 |
1691 test_undefinedFunction_inCatch() async { | 1447 test_undefinedFunction_inCatch() async { |
1692 await assertErrorsInCode( | 1448 await assertErrorsInCode(r''' |
1693 r''' | |
1694 void f() { | 1449 void f() { |
1695 try { | 1450 try { |
1696 } on Object { | 1451 } on Object { |
1697 g(); | 1452 g(); |
1698 } | 1453 } |
1699 }''', | 1454 }''', [StaticTypeWarningCode.UNDEFINED_FUNCTION]); |
1700 [StaticTypeWarningCode.UNDEFINED_FUNCTION]); | |
1701 } | 1455 } |
1702 | 1456 |
1703 test_undefinedFunction_inImportedLib() async { | 1457 test_undefinedFunction_inImportedLib() async { |
1704 Source source = addSource(r''' | 1458 Source source = addSource(r''' |
1705 import 'lib.dart' as f; | 1459 import 'lib.dart' as f; |
1706 main() { return f.g(); }'''); | 1460 main() { return f.g(); }'''); |
1707 addNamedSource( | 1461 addNamedSource("/lib.dart", r''' |
1708 "/lib.dart", | |
1709 r''' | |
1710 library lib; | 1462 library lib; |
1711 h() {}'''); | 1463 h() {}'''); |
1712 await computeAnalysisResult(source); | 1464 await computeAnalysisResult(source); |
1713 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_FUNCTION]); | 1465 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_FUNCTION]); |
1714 } | 1466 } |
1715 | 1467 |
1716 test_undefinedGetter() async { | 1468 test_undefinedGetter() async { |
1717 await assertErrorsInUnverifiedCode( | 1469 await assertErrorsInUnverifiedCode(r''' |
1718 r''' | |
1719 class T {} | 1470 class T {} |
1720 f(T e) { return e.m; }''', | 1471 f(T e) { return e.m; }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1721 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1722 } | 1472 } |
1723 | 1473 |
1724 test_undefinedGetter_generic_function_call() async { | 1474 test_undefinedGetter_generic_function_call() async { |
1725 // Objects having a specific function type have a call() method, but | 1475 // Objects having a specific function type have a call() method, but |
1726 // objects having type Function do not (this is because it is impossible to | 1476 // objects having type Function do not (this is because it is impossible to |
1727 // know what signature the call should have). | 1477 // know what signature the call should have). |
1728 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 1478 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
1729 options.enableStrictCallChecks = true; | 1479 options.enableStrictCallChecks = true; |
1730 resetWith(options: options); | 1480 resetWith(options: options); |
1731 await assertErrorsInUnverifiedCode( | 1481 await assertErrorsInUnverifiedCode(''' |
1732 ''' | |
1733 f(Function f) { | 1482 f(Function f) { |
1734 return f.call; | 1483 return f.call; |
1735 } | 1484 } |
1736 ''', | 1485 ''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1737 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1738 } | 1486 } |
1739 | 1487 |
1740 test_undefinedGetter_object_call() async { | 1488 test_undefinedGetter_object_call() async { |
1741 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 1489 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
1742 options.enableStrictCallChecks = true; | 1490 options.enableStrictCallChecks = true; |
1743 resetWith(options: options); | 1491 resetWith(options: options); |
1744 await assertErrorsInUnverifiedCode( | 1492 await assertErrorsInUnverifiedCode(''' |
1745 ''' | |
1746 f(Object o) { | 1493 f(Object o) { |
1747 return o.call; | 1494 return o.call; |
1748 } | 1495 } |
1749 ''', | 1496 ''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1750 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1751 } | 1497 } |
1752 | 1498 |
1753 test_undefinedGetter_proxy_annotation_fakeProxy() async { | 1499 test_undefinedGetter_proxy_annotation_fakeProxy() async { |
1754 await assertErrorsInCode( | 1500 await assertErrorsInCode(r''' |
1755 r''' | |
1756 library L; | 1501 library L; |
1757 class Fake { | 1502 class Fake { |
1758 const Fake(); | 1503 const Fake(); |
1759 } | 1504 } |
1760 const proxy = const Fake(); | 1505 const proxy = const Fake(); |
1761 @proxy class PrefixProxy {} | 1506 @proxy class PrefixProxy {} |
1762 main() { | 1507 main() { |
1763 new PrefixProxy().foo; | 1508 new PrefixProxy().foo; |
1764 }''', | 1509 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1765 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1766 } | 1510 } |
1767 | 1511 |
1768 test_undefinedGetter_static() async { | 1512 test_undefinedGetter_static() async { |
1769 await assertErrorsInUnverifiedCode( | 1513 await assertErrorsInUnverifiedCode(r''' |
1770 r''' | |
1771 class A {} | 1514 class A {} |
1772 var a = A.B;''', | 1515 var a = A.B;''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1773 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1774 } | 1516 } |
1775 | 1517 |
1776 test_undefinedGetter_typeLiteral_cascadeTarget() async { | 1518 test_undefinedGetter_typeLiteral_cascadeTarget() async { |
1777 await assertErrorsInCode( | 1519 await assertErrorsInCode(r''' |
1778 r''' | |
1779 class T { | 1520 class T { |
1780 static int get foo => 42; | 1521 static int get foo => 42; |
1781 } | 1522 } |
1782 main() { | 1523 main() { |
1783 T..foo; | 1524 T..foo; |
1784 }''', | 1525 }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1785 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1786 } | 1526 } |
1787 | 1527 |
1788 test_undefinedGetter_typeLiteral_conditionalAccess() async { | 1528 test_undefinedGetter_typeLiteral_conditionalAccess() async { |
1789 // When applied to a type literal, the conditional access operator '?.' | 1529 // When applied to a type literal, the conditional access operator '?.' |
1790 // cannot be used to access instance getters of Type. | 1530 // cannot be used to access instance getters of Type. |
1791 await assertErrorsInCode( | 1531 await assertErrorsInCode(''' |
1792 ''' | |
1793 class A {} | 1532 class A {} |
1794 f() => A?.hashCode; | 1533 f() => A?.hashCode; |
1795 ''', | 1534 ''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1796 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1797 } | 1535 } |
1798 | 1536 |
1799 test_undefinedGetter_void() async { | 1537 test_undefinedGetter_void() async { |
1800 await assertErrorsInCode( | 1538 await assertErrorsInCode(r''' |
1801 r''' | |
1802 class T { | 1539 class T { |
1803 void m() {} | 1540 void m() {} |
1804 } | 1541 } |
1805 f(T e) { return e.m().f; }''', | 1542 f(T e) { return e.m().f; }''', [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1806 [StaticTypeWarningCode.UNDEFINED_GETTER]); | |
1807 } | 1543 } |
1808 | 1544 |
1809 test_undefinedGetter_wrongNumberOfTypeArguments_tooLittle() async { | 1545 test_undefinedGetter_wrongNumberOfTypeArguments_tooLittle() async { |
1810 await assertErrorsInCode( | 1546 await assertErrorsInCode(r''' |
1811 r''' | |
1812 class A<K, V> { | 1547 class A<K, V> { |
1813 K element; | 1548 K element; |
1814 } | 1549 } |
1815 main(A<int> a) { | 1550 main(A<int> a) { |
1816 a.element.anyGetterExistsInDynamic; | 1551 a.element.anyGetterExistsInDynamic; |
1817 }''', | 1552 }''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); |
1818 [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); | |
1819 } | 1553 } |
1820 | 1554 |
1821 test_undefinedGetter_wrongNumberOfTypeArguments_tooMany() async { | 1555 test_undefinedGetter_wrongNumberOfTypeArguments_tooMany() async { |
1822 await assertErrorsInCode( | 1556 await assertErrorsInCode(r''' |
1823 r''' | |
1824 class A<E> { | 1557 class A<E> { |
1825 E element; | 1558 E element; |
1826 } | 1559 } |
1827 main(A<int,int> a) { | 1560 main(A<int,int> a) { |
1828 a.element.anyGetterExistsInDynamic; | 1561 a.element.anyGetterExistsInDynamic; |
1829 }''', | 1562 }''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); |
1830 [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); | |
1831 } | 1563 } |
1832 | 1564 |
1833 test_undefinedGetter_wrongOfTypeArgument() async { | 1565 test_undefinedGetter_wrongOfTypeArgument() async { |
1834 await assertErrorsInCode( | 1566 await assertErrorsInCode(r''' |
1835 r''' | |
1836 class A<E> { | 1567 class A<E> { |
1837 E element; | 1568 E element; |
1838 } | 1569 } |
1839 main(A<NoSuchType> a) { | 1570 main(A<NoSuchType> a) { |
1840 a.element.anyGetterExistsInDynamic; | 1571 a.element.anyGetterExistsInDynamic; |
1841 }''', | 1572 }''', [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]); |
1842 [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]); | |
1843 } | 1573 } |
1844 | 1574 |
1845 test_undefinedMethod() async { | 1575 test_undefinedMethod() async { |
1846 await assertErrorsInCode( | 1576 await assertErrorsInCode(r''' |
1847 r''' | |
1848 class A { | 1577 class A { |
1849 void m() { | 1578 void m() { |
1850 n(); | 1579 n(); |
1851 } | 1580 } |
1852 }''', | 1581 }''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1853 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1854 } | 1582 } |
1855 | 1583 |
1856 test_undefinedMethod_assignmentExpression() async { | 1584 test_undefinedMethod_assignmentExpression() async { |
1857 await assertErrorsInCode( | 1585 await assertErrorsInCode(r''' |
1858 r''' | |
1859 class A {} | 1586 class A {} |
1860 class B { | 1587 class B { |
1861 f(A a) { | 1588 f(A a) { |
1862 A a2 = new A(); | 1589 A a2 = new A(); |
1863 a += a2; | 1590 a += a2; |
1864 } | 1591 } |
1865 }''', | 1592 }''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1866 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1867 } | 1593 } |
1868 | 1594 |
1869 test_undefinedMethod_generic_function_call() async { | 1595 test_undefinedMethod_generic_function_call() async { |
1870 // Objects having a specific function type have a call() method, but | 1596 // Objects having a specific function type have a call() method, but |
1871 // objects having type Function do not (this is because it is impossible to | 1597 // objects having type Function do not (this is because it is impossible to |
1872 // know what signature the call should have). | 1598 // know what signature the call should have). |
1873 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 1599 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
1874 options.enableStrictCallChecks = true; | 1600 options.enableStrictCallChecks = true; |
1875 resetWith(options: options); | 1601 resetWith(options: options); |
1876 await assertErrorsInCode( | 1602 await assertErrorsInCode(''' |
1877 ''' | |
1878 f(Function f) { | 1603 f(Function f) { |
1879 f.call(); | 1604 f.call(); |
1880 } | 1605 } |
1881 ''', | 1606 ''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1882 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1883 } | 1607 } |
1884 | 1608 |
1885 test_undefinedMethod_ignoreTypePropagation() async { | 1609 test_undefinedMethod_ignoreTypePropagation() async { |
1886 await assertErrorsInCode( | 1610 await assertErrorsInCode(r''' |
1887 r''' | |
1888 class A {} | 1611 class A {} |
1889 class B extends A { | 1612 class B extends A { |
1890 m() {} | 1613 m() {} |
1891 } | 1614 } |
1892 class C { | 1615 class C { |
1893 f() { | 1616 f() { |
1894 A a = new B(); | 1617 A a = new B(); |
1895 a.m(); | 1618 a.m(); |
1896 } | 1619 } |
1897 }''', | 1620 }''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1898 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1899 } | 1621 } |
1900 | 1622 |
1901 test_undefinedMethod_leastUpperBoundWithNull() async { | 1623 test_undefinedMethod_leastUpperBoundWithNull() async { |
1902 await assertErrorsInCode('f(bool b, int i) => (b ? null : i).foo();', | 1624 await assertErrorsInCode('f(bool b, int i) => (b ? null : i).foo();', |
1903 [StaticTypeWarningCode.UNDEFINED_METHOD]); | 1625 [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1904 } | 1626 } |
1905 | 1627 |
1906 test_undefinedMethod_object_call() async { | 1628 test_undefinedMethod_object_call() async { |
1907 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 1629 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
1908 options.enableStrictCallChecks = true; | 1630 options.enableStrictCallChecks = true; |
1909 resetWith(options: options); | 1631 resetWith(options: options); |
1910 await assertErrorsInCode( | 1632 await assertErrorsInCode(''' |
1911 ''' | |
1912 f(Object o) { | 1633 f(Object o) { |
1913 o.call(); | 1634 o.call(); |
1914 } | 1635 } |
1915 ''', | 1636 ''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1916 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1917 } | 1637 } |
1918 | 1638 |
1919 test_undefinedMethod_ofNull() async { | 1639 test_undefinedMethod_ofNull() async { |
1920 // TODO(scheglov) Track https://github.com/dart-lang/sdk/issues/28430 to | 1640 // TODO(scheglov) Track https://github.com/dart-lang/sdk/issues/28430 to |
1921 // decide whether a warning should be reported here. | 1641 // decide whether a warning should be reported here. |
1922 await assertErrorsInCode( | 1642 await assertErrorsInCode(r''' |
1923 r''' | |
1924 Null f(int x) => null; | 1643 Null f(int x) => null; |
1925 main() { | 1644 main() { |
1926 f(42).abs(); | 1645 f(42).abs(); |
1927 } | 1646 } |
1928 ''', | 1647 ''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1929 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1930 } | 1648 } |
1931 | 1649 |
1932 test_undefinedMethod_private() async { | 1650 test_undefinedMethod_private() async { |
1933 addNamedSource( | 1651 addNamedSource("/lib.dart", r''' |
1934 "/lib.dart", | |
1935 r''' | |
1936 library lib; | 1652 library lib; |
1937 class A { | 1653 class A { |
1938 _foo() {} | 1654 _foo() {} |
1939 }'''); | 1655 }'''); |
1940 await assertErrorsInCode( | 1656 await assertErrorsInCode(r''' |
1941 r''' | |
1942 import 'lib.dart'; | 1657 import 'lib.dart'; |
1943 class B extends A { | 1658 class B extends A { |
1944 test() { | 1659 test() { |
1945 _foo(); | 1660 _foo(); |
1946 } | 1661 } |
1947 }''', | 1662 }''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1948 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1949 } | 1663 } |
1950 | 1664 |
1951 test_undefinedMethod_proxy_annotation_fakeProxy() async { | 1665 test_undefinedMethod_proxy_annotation_fakeProxy() async { |
1952 await assertErrorsInCode( | 1666 await assertErrorsInCode(r''' |
1953 r''' | |
1954 library L; | 1667 library L; |
1955 class Fake { | 1668 class Fake { |
1956 const Fake(); | 1669 const Fake(); |
1957 } | 1670 } |
1958 const proxy = const Fake(); | 1671 const proxy = const Fake(); |
1959 @proxy class PrefixProxy {} | 1672 @proxy class PrefixProxy {} |
1960 main() { | 1673 main() { |
1961 new PrefixProxy().foo(); | 1674 new PrefixProxy().foo(); |
1962 }''', | 1675 }''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1963 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1964 } | 1676 } |
1965 | 1677 |
1966 test_undefinedMethod_typeLiteral_cascadeTarget() async { | 1678 test_undefinedMethod_typeLiteral_cascadeTarget() async { |
1967 await assertErrorsInCode( | 1679 await assertErrorsInCode(''' |
1968 ''' | |
1969 class T { | 1680 class T { |
1970 static void foo() {} | 1681 static void foo() {} |
1971 } | 1682 } |
1972 main() { | 1683 main() { |
1973 T..foo(); | 1684 T..foo(); |
1974 } | 1685 } |
1975 ''', | 1686 ''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1976 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1977 } | 1687 } |
1978 | 1688 |
1979 test_undefinedMethod_typeLiteral_conditionalAccess() async { | 1689 test_undefinedMethod_typeLiteral_conditionalAccess() async { |
1980 // When applied to a type literal, the conditional access operator '?.' | 1690 // When applied to a type literal, the conditional access operator '?.' |
1981 // cannot be used to access instance methods of Type. | 1691 // cannot be used to access instance methods of Type. |
1982 await assertErrorsInCode( | 1692 await assertErrorsInCode(''' |
1983 ''' | |
1984 class A {} | 1693 class A {} |
1985 f() => A?.toString(); | 1694 f() => A?.toString(); |
1986 ''', | 1695 ''', [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1987 [StaticTypeWarningCode.UNDEFINED_METHOD]); | |
1988 } | 1696 } |
1989 | 1697 |
1990 test_undefinedMethodWithConstructor() async { | 1698 test_undefinedMethodWithConstructor() async { |
1991 await assertErrorsInCode( | 1699 await assertErrorsInCode(r''' |
1992 r''' | |
1993 class C { | 1700 class C { |
1994 C.m(); | 1701 C.m(); |
1995 } | 1702 } |
1996 f() { | 1703 f() { |
1997 C c = C.m(); | 1704 C c = C.m(); |
1998 }''', | 1705 }''', [StaticTypeWarningCode.UNDEFINED_METHOD_WITH_CONSTRUCTOR]); |
1999 [StaticTypeWarningCode.UNDEFINED_METHOD_WITH_CONSTRUCTOR]); | |
2000 } | 1706 } |
2001 | 1707 |
2002 test_undefinedOperator_indexBoth() async { | 1708 test_undefinedOperator_indexBoth() async { |
2003 await assertErrorsInUnverifiedCode( | 1709 await assertErrorsInUnverifiedCode(r''' |
2004 r''' | |
2005 class A {} | 1710 class A {} |
2006 f(A a) { | 1711 f(A a) { |
2007 a[0]++; | 1712 a[0]++; |
2008 }''', | 1713 }''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
2009 [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | |
2010 } | 1714 } |
2011 | 1715 |
2012 test_undefinedOperator_indexGetter() async { | 1716 test_undefinedOperator_indexGetter() async { |
2013 await assertErrorsInUnverifiedCode( | 1717 await assertErrorsInUnverifiedCode(r''' |
2014 r''' | |
2015 class A {} | 1718 class A {} |
2016 f(A a) { | 1719 f(A a) { |
2017 a[0]; | 1720 a[0]; |
2018 }''', | 1721 }''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
2019 [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | |
2020 } | 1722 } |
2021 | 1723 |
2022 test_undefinedOperator_indexSetter() async { | 1724 test_undefinedOperator_indexSetter() async { |
2023 await assertErrorsInUnverifiedCode( | 1725 await assertErrorsInUnverifiedCode(r''' |
2024 r''' | |
2025 class A {} | 1726 class A {} |
2026 f(A a) { | 1727 f(A a) { |
2027 a[0] = 1; | 1728 a[0] = 1; |
2028 }''', | 1729 }''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
2029 [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | |
2030 } | 1730 } |
2031 | 1731 |
2032 test_undefinedOperator_plus() async { | 1732 test_undefinedOperator_plus() async { |
2033 await assertErrorsInUnverifiedCode( | 1733 await assertErrorsInUnverifiedCode(r''' |
2034 r''' | |
2035 class A {} | 1734 class A {} |
2036 f(A a) { | 1735 f(A a) { |
2037 a + 1; | 1736 a + 1; |
2038 }''', | 1737 }''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
2039 [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | |
2040 } | 1738 } |
2041 | 1739 |
2042 test_undefinedOperator_postfixExpression() async { | 1740 test_undefinedOperator_postfixExpression() async { |
2043 await assertErrorsInCode( | 1741 await assertErrorsInCode(r''' |
2044 r''' | |
2045 class A {} | 1742 class A {} |
2046 f(A a) { | 1743 f(A a) { |
2047 a++; | 1744 a++; |
2048 }''', | 1745 }''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
2049 [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | |
2050 } | 1746 } |
2051 | 1747 |
2052 test_undefinedOperator_prefixExpression() async { | 1748 test_undefinedOperator_prefixExpression() async { |
2053 await assertErrorsInCode( | 1749 await assertErrorsInCode(r''' |
2054 r''' | |
2055 class A {} | 1750 class A {} |
2056 f(A a) { | 1751 f(A a) { |
2057 ++a; | 1752 ++a; |
2058 }''', | 1753 }''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
2059 [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | |
2060 } | 1754 } |
2061 | 1755 |
2062 test_undefinedSetter() async { | 1756 test_undefinedSetter() async { |
2063 await assertErrorsInUnverifiedCode( | 1757 await assertErrorsInUnverifiedCode(r''' |
2064 r''' | |
2065 class T {} | 1758 class T {} |
2066 f(T e1) { e1.m = 0; }''', | 1759 f(T e1) { e1.m = 0; }''', [StaticTypeWarningCode.UNDEFINED_SETTER]); |
2067 [StaticTypeWarningCode.UNDEFINED_SETTER]); | |
2068 } | 1760 } |
2069 | 1761 |
2070 test_undefinedSetter_static() async { | 1762 test_undefinedSetter_static() async { |
2071 await assertErrorsInUnverifiedCode( | 1763 await assertErrorsInUnverifiedCode(r''' |
2072 r''' | |
2073 class A {} | 1764 class A {} |
2074 f() { A.B = 0;}''', | 1765 f() { A.B = 0;}''', [StaticTypeWarningCode.UNDEFINED_SETTER]); |
2075 [StaticTypeWarningCode.UNDEFINED_SETTER]); | |
2076 } | 1766 } |
2077 | 1767 |
2078 test_undefinedSetter_typeLiteral_cascadeTarget() async { | 1768 test_undefinedSetter_typeLiteral_cascadeTarget() async { |
2079 await assertErrorsInCode( | 1769 await assertErrorsInCode(r''' |
2080 r''' | |
2081 class T { | 1770 class T { |
2082 static void set foo(_) {} | 1771 static void set foo(_) {} |
2083 } | 1772 } |
2084 main() { | 1773 main() { |
2085 T..foo = 42; | 1774 T..foo = 42; |
2086 }''', | 1775 }''', [StaticTypeWarningCode.UNDEFINED_SETTER]); |
2087 [StaticTypeWarningCode.UNDEFINED_SETTER]); | |
2088 } | 1776 } |
2089 | 1777 |
2090 test_undefinedSetter_void() async { | 1778 test_undefinedSetter_void() async { |
2091 await assertErrorsInCode( | 1779 await assertErrorsInCode(r''' |
2092 r''' | |
2093 class T { | 1780 class T { |
2094 void m() {} | 1781 void m() {} |
2095 } | 1782 } |
2096 f(T e) { e.m().f = 0; }''', | 1783 f(T e) { e.m().f = 0; }''', [StaticTypeWarningCode.UNDEFINED_SETTER]); |
2097 [StaticTypeWarningCode.UNDEFINED_SETTER]); | |
2098 } | 1784 } |
2099 | 1785 |
2100 test_undefinedSuperGetter() async { | 1786 test_undefinedSuperGetter() async { |
2101 await assertErrorsInCode( | 1787 await assertErrorsInCode(r''' |
2102 r''' | |
2103 class A {} | 1788 class A {} |
2104 class B extends A { | 1789 class B extends A { |
2105 get g { | 1790 get g { |
2106 return super.g; | 1791 return super.g; |
2107 } | 1792 } |
2108 }''', | 1793 }''', [StaticTypeWarningCode.UNDEFINED_SUPER_GETTER]); |
2109 [StaticTypeWarningCode.UNDEFINED_SUPER_GETTER]); | |
2110 } | 1794 } |
2111 | 1795 |
2112 test_undefinedSuperMethod() async { | 1796 test_undefinedSuperMethod() async { |
2113 await assertErrorsInCode( | 1797 await assertErrorsInCode(r''' |
2114 r''' | |
2115 class A {} | 1798 class A {} |
2116 class B extends A { | 1799 class B extends A { |
2117 m() { return super.m(); } | 1800 m() { return super.m(); } |
2118 }''', | 1801 }''', [StaticTypeWarningCode.UNDEFINED_SUPER_METHOD]); |
2119 [StaticTypeWarningCode.UNDEFINED_SUPER_METHOD]); | |
2120 } | 1802 } |
2121 | 1803 |
2122 test_undefinedSuperOperator_binaryExpression() async { | 1804 test_undefinedSuperOperator_binaryExpression() async { |
2123 await assertErrorsInUnverifiedCode( | 1805 await assertErrorsInUnverifiedCode(r''' |
2124 r''' | |
2125 class A {} | 1806 class A {} |
2126 class B extends A { | 1807 class B extends A { |
2127 operator +(value) { | 1808 operator +(value) { |
2128 return super + value; | 1809 return super + value; |
2129 } | 1810 } |
2130 }''', | 1811 }''', [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]); |
2131 [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]); | |
2132 } | 1812 } |
2133 | 1813 |
2134 test_undefinedSuperOperator_indexBoth() async { | 1814 test_undefinedSuperOperator_indexBoth() async { |
2135 await assertErrorsInUnverifiedCode( | 1815 await assertErrorsInUnverifiedCode(r''' |
2136 r''' | |
2137 class A {} | 1816 class A {} |
2138 class B extends A { | 1817 class B extends A { |
2139 operator [](index) { | 1818 operator [](index) { |
2140 return super[index]++; | 1819 return super[index]++; |
2141 } | 1820 } |
2142 }''', | 1821 }''', [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]); |
2143 [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]); | |
2144 } | 1822 } |
2145 | 1823 |
2146 test_undefinedSuperOperator_indexGetter() async { | 1824 test_undefinedSuperOperator_indexGetter() async { |
2147 await assertErrorsInUnverifiedCode( | 1825 await assertErrorsInUnverifiedCode(r''' |
2148 r''' | |
2149 class A {} | 1826 class A {} |
2150 class B extends A { | 1827 class B extends A { |
2151 operator [](index) { | 1828 operator [](index) { |
2152 return super[index + 1]; | 1829 return super[index + 1]; |
2153 } | 1830 } |
2154 }''', | 1831 }''', [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]); |
2155 [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]); | |
2156 } | 1832 } |
2157 | 1833 |
2158 test_undefinedSuperOperator_indexSetter() async { | 1834 test_undefinedSuperOperator_indexSetter() async { |
2159 await assertErrorsInUnverifiedCode( | 1835 await assertErrorsInUnverifiedCode(r''' |
2160 r''' | |
2161 class A {} | 1836 class A {} |
2162 class B extends A { | 1837 class B extends A { |
2163 operator []=(index, value) { | 1838 operator []=(index, value) { |
2164 return super[index] = 0; | 1839 return super[index] = 0; |
2165 } | 1840 } |
2166 }''', | 1841 }''', [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]); |
2167 [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]); | |
2168 } | 1842 } |
2169 | 1843 |
2170 test_undefinedSuperSetter() async { | 1844 test_undefinedSuperSetter() async { |
2171 await assertErrorsInCode( | 1845 await assertErrorsInCode(r''' |
2172 r''' | |
2173 class A {} | 1846 class A {} |
2174 class B extends A { | 1847 class B extends A { |
2175 f() { | 1848 f() { |
2176 super.m = 0; | 1849 super.m = 0; |
2177 } | 1850 } |
2178 }''', | 1851 }''', [StaticTypeWarningCode.UNDEFINED_SUPER_SETTER]); |
2179 [StaticTypeWarningCode.UNDEFINED_SUPER_SETTER]); | |
2180 } | 1852 } |
2181 | 1853 |
2182 test_unqualifiedReferenceToNonLocalStaticMember_getter() async { | 1854 test_unqualifiedReferenceToNonLocalStaticMember_getter() async { |
2183 await assertErrorsInCode( | 1855 await assertErrorsInCode(r''' |
2184 r''' | |
2185 class A { | 1856 class A { |
2186 static int get a => 0; | 1857 static int get a => 0; |
2187 } | 1858 } |
2188 class B extends A { | 1859 class B extends A { |
2189 int b() { | 1860 int b() { |
2190 return a; | 1861 return a; |
2191 } | 1862 } |
2192 }''', | 1863 }''', [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER]); |
2193 [ | |
2194 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER | |
2195 ]); | |
2196 } | 1864 } |
2197 | 1865 |
2198 test_unqualifiedReferenceToNonLocalStaticMember_getter_invokeTarget() async { | 1866 test_unqualifiedReferenceToNonLocalStaticMember_getter_invokeTarget() async { |
2199 await assertErrorsInCode( | 1867 await assertErrorsInCode(r''' |
2200 r''' | |
2201 class A { | 1868 class A { |
2202 static int foo; | 1869 static int foo; |
2203 } | 1870 } |
2204 | 1871 |
2205 class B extends A { | 1872 class B extends A { |
2206 static bar() { | 1873 static bar() { |
2207 foo.abs(); | 1874 foo.abs(); |
2208 } | 1875 } |
2209 } | 1876 } |
2210 ''', | 1877 ''', [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER]); |
2211 [ | |
2212 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER | |
2213 ]); | |
2214 } | 1878 } |
2215 | 1879 |
2216 test_unqualifiedReferenceToNonLocalStaticMember_method() async { | 1880 test_unqualifiedReferenceToNonLocalStaticMember_method() async { |
2217 await assertErrorsInCode( | 1881 await assertErrorsInCode(r''' |
2218 r''' | |
2219 class A { | 1882 class A { |
2220 static void a() {} | 1883 static void a() {} |
2221 } | 1884 } |
2222 class B extends A { | 1885 class B extends A { |
2223 void b() { | 1886 void b() { |
2224 a(); | 1887 a(); |
2225 } | 1888 } |
2226 }''', | 1889 }''', [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER]); |
2227 [ | |
2228 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER | |
2229 ]); | |
2230 } | 1890 } |
2231 | 1891 |
2232 test_unqualifiedReferenceToNonLocalStaticMember_setter() async { | 1892 test_unqualifiedReferenceToNonLocalStaticMember_setter() async { |
2233 await assertErrorsInCode( | 1893 await assertErrorsInCode(r''' |
2234 r''' | |
2235 class A { | 1894 class A { |
2236 static set a(x) {} | 1895 static set a(x) {} |
2237 } | 1896 } |
2238 class B extends A { | 1897 class B extends A { |
2239 b(y) { | 1898 b(y) { |
2240 a = y; | 1899 a = y; |
2241 } | 1900 } |
2242 }''', | 1901 }''', [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER]); |
2243 [ | |
2244 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER | |
2245 ]); | |
2246 } | 1902 } |
2247 | 1903 |
2248 test_wrongNumberOfTypeArguments_classAlias() async { | 1904 test_wrongNumberOfTypeArguments_classAlias() async { |
2249 await assertErrorsInCode( | 1905 await assertErrorsInCode(r''' |
2250 r''' | |
2251 class A {} | 1906 class A {} |
2252 class M {} | 1907 class M {} |
2253 class B<F extends num> = A<F> with M;''', | 1908 class B<F extends num> = A<F> with M;''', |
2254 [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); | 1909 [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); |
2255 } | 1910 } |
2256 | 1911 |
2257 test_wrongNumberOfTypeArguments_tooFew() async { | 1912 test_wrongNumberOfTypeArguments_tooFew() async { |
2258 await assertErrorsInCode( | 1913 await assertErrorsInCode(r''' |
2259 r''' | |
2260 class A<E, F> {} | 1914 class A<E, F> {} |
2261 A<A> a = null;''', | 1915 A<A> a = null;''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); |
2262 [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); | |
2263 } | 1916 } |
2264 | 1917 |
2265 test_wrongNumberOfTypeArguments_tooMany() async { | 1918 test_wrongNumberOfTypeArguments_tooMany() async { |
2266 await assertErrorsInCode( | 1919 await assertErrorsInCode(r''' |
2267 r''' | |
2268 class A<E> {} | 1920 class A<E> {} |
2269 A<A, A> a = null;''', | 1921 A<A, A> a = null;''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); |
2270 [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); | |
2271 } | 1922 } |
2272 | 1923 |
2273 test_wrongNumberOfTypeArguments_typeTest_tooFew() async { | 1924 test_wrongNumberOfTypeArguments_typeTest_tooFew() async { |
2274 await assertErrorsInCode( | 1925 await assertErrorsInCode(r''' |
2275 r''' | |
2276 class A {} | 1926 class A {} |
2277 class C<K, V> {} | 1927 class C<K, V> {} |
2278 f(p) { | 1928 f(p) { |
2279 return p is C<A>; | 1929 return p is C<A>; |
2280 }''', | 1930 }''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); |
2281 [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); | |
2282 } | 1931 } |
2283 | 1932 |
2284 test_wrongNumberOfTypeArguments_typeTest_tooMany() async { | 1933 test_wrongNumberOfTypeArguments_typeTest_tooMany() async { |
2285 await assertErrorsInCode( | 1934 await assertErrorsInCode(r''' |
2286 r''' | |
2287 class A {} | 1935 class A {} |
2288 class C<E> {} | 1936 class C<E> {} |
2289 f(p) { | 1937 f(p) { |
2290 return p is C<A, A>; | 1938 return p is C<A, A>; |
2291 }''', | 1939 }''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); |
2292 [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); | |
2293 } | 1940 } |
2294 | 1941 |
2295 test_yield_async_to_basic_type() async { | 1942 test_yield_async_to_basic_type() async { |
2296 await assertErrorsInCode( | 1943 await assertErrorsInCode(''' |
2297 ''' | |
2298 int f() async* { | 1944 int f() async* { |
2299 yield 3; | 1945 yield 3; |
2300 } | 1946 } |
2301 ''', | 1947 ''', [ |
2302 [ | 1948 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
2303 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, | 1949 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE |
2304 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE | 1950 ]); |
2305 ]); | |
2306 } | 1951 } |
2307 | 1952 |
2308 test_yield_async_to_iterable() async { | 1953 test_yield_async_to_iterable() async { |
2309 await assertErrorsInCode( | 1954 await assertErrorsInCode(''' |
2310 ''' | |
2311 Iterable<int> f() async* { | 1955 Iterable<int> f() async* { |
2312 yield 3; | 1956 yield 3; |
2313 } | 1957 } |
2314 ''', | 1958 ''', [ |
2315 [ | 1959 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
2316 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, | 1960 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE |
2317 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE | 1961 ]); |
2318 ]); | |
2319 } | 1962 } |
2320 | 1963 |
2321 test_yield_async_to_mistyped_stream() async { | 1964 test_yield_async_to_mistyped_stream() async { |
2322 await assertErrorsInCode( | 1965 await assertErrorsInCode(''' |
2323 ''' | |
2324 import 'dart:async'; | 1966 import 'dart:async'; |
2325 Stream<int> f() async* { | 1967 Stream<int> f() async* { |
2326 yield "foo"; | 1968 yield "foo"; |
2327 } | 1969 } |
2328 ''', | 1970 ''', [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); |
2329 [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); | |
2330 } | 1971 } |
2331 | 1972 |
2332 test_yield_each_async_non_stream() async { | 1973 test_yield_each_async_non_stream() async { |
2333 await assertErrorsInCode( | 1974 await assertErrorsInCode(''' |
2334 ''' | |
2335 f() async* { | 1975 f() async* { |
2336 yield* 0; | 1976 yield* 0; |
2337 } | 1977 } |
2338 ''', | 1978 ''', [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); |
2339 [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); | |
2340 } | 1979 } |
2341 | 1980 |
2342 test_yield_each_async_to_mistyped_stream() async { | 1981 test_yield_each_async_to_mistyped_stream() async { |
2343 await assertErrorsInCode( | 1982 await assertErrorsInCode(''' |
2344 ''' | |
2345 import 'dart:async'; | 1983 import 'dart:async'; |
2346 Stream<int> f() async* { | 1984 Stream<int> f() async* { |
2347 yield* g(); | 1985 yield* g(); |
2348 } | 1986 } |
2349 Stream<String> g() => null; | 1987 Stream<String> g() => null; |
2350 ''', | 1988 ''', [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); |
2351 [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); | |
2352 } | 1989 } |
2353 | 1990 |
2354 test_yield_each_sync_non_iterable() async { | 1991 test_yield_each_sync_non_iterable() async { |
2355 await assertErrorsInCode( | 1992 await assertErrorsInCode(''' |
2356 ''' | |
2357 f() sync* { | 1993 f() sync* { |
2358 yield* 0; | 1994 yield* 0; |
2359 } | 1995 } |
2360 ''', | 1996 ''', [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); |
2361 [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); | |
2362 } | 1997 } |
2363 | 1998 |
2364 test_yield_each_sync_to_mistyped_iterable() async { | 1999 test_yield_each_sync_to_mistyped_iterable() async { |
2365 await assertErrorsInCode( | 2000 await assertErrorsInCode(''' |
2366 ''' | |
2367 Iterable<int> f() sync* { | 2001 Iterable<int> f() sync* { |
2368 yield* g(); | 2002 yield* g(); |
2369 } | 2003 } |
2370 Iterable<String> g() => null; | 2004 Iterable<String> g() => null; |
2371 ''', | 2005 ''', [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); |
2372 [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); | |
2373 } | 2006 } |
2374 | 2007 |
2375 test_yield_sync_to_basic_type() async { | 2008 test_yield_sync_to_basic_type() async { |
2376 await assertErrorsInCode( | 2009 await assertErrorsInCode(''' |
2377 ''' | |
2378 int f() sync* { | 2010 int f() sync* { |
2379 yield 3; | 2011 yield 3; |
2380 } | 2012 } |
2381 ''', | 2013 ''', [ |
2382 [ | 2014 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
2383 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, | 2015 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE |
2384 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE | 2016 ]); |
2385 ]); | |
2386 } | 2017 } |
2387 | 2018 |
2388 test_yield_sync_to_mistyped_iterable() async { | 2019 test_yield_sync_to_mistyped_iterable() async { |
2389 await assertErrorsInCode( | 2020 await assertErrorsInCode(''' |
2390 ''' | |
2391 Iterable<int> f() sync* { | 2021 Iterable<int> f() sync* { |
2392 yield "foo"; | 2022 yield "foo"; |
2393 } | 2023 } |
2394 ''', | 2024 ''', [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); |
2395 [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]); | |
2396 } | 2025 } |
2397 | 2026 |
2398 test_yield_sync_to_stream() async { | 2027 test_yield_sync_to_stream() async { |
2399 await assertErrorsInCode( | 2028 await assertErrorsInCode(''' |
2400 ''' | |
2401 import 'dart:async'; | 2029 import 'dart:async'; |
2402 Stream<int> f() sync* { | 2030 Stream<int> f() sync* { |
2403 yield 3; | 2031 yield 3; |
2404 } | 2032 } |
2405 ''', | 2033 ''', [ |
2406 [ | 2034 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
2407 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, | 2035 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE |
2408 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE | 2036 ]); |
2409 ]); | |
2410 } | 2037 } |
2411 } | 2038 } |
2412 | 2039 |
2413 @reflectiveTest | 2040 @reflectiveTest |
2414 class StrongModeStaticTypeWarningCodeTest extends ResolverTestCase { | 2041 class StrongModeStaticTypeWarningCodeTest extends ResolverTestCase { |
2415 void setUp() { | 2042 void setUp() { |
2416 super.setUp(); | 2043 super.setUp(); |
2417 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 2044 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
2418 options.strongMode = true; | 2045 options.strongMode = true; |
2419 resetWith(options: options); | 2046 resetWith(options: options); |
(...skipping 13 matching lines...) Expand all Loading... |
2433 if (error.errorCode == | 2060 if (error.errorCode == |
2434 StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS) { | 2061 StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS) { |
2435 expect(error.message, | 2062 expect(error.message, |
2436 formatList(error.errorCode.message, ['() → dynamic', 0, 1])); | 2063 formatList(error.errorCode.message, ['() → dynamic', 0, 1])); |
2437 } | 2064 } |
2438 } | 2065 } |
2439 verify([source]); | 2066 verify([source]); |
2440 } | 2067 } |
2441 | 2068 |
2442 test_legalAsyncGeneratorReturnType_function_supertypeOfStream() async { | 2069 test_legalAsyncGeneratorReturnType_function_supertypeOfStream() async { |
2443 await assertErrorsInCode( | 2070 await assertErrorsInCode(''' |
2444 ''' | |
2445 import 'dart:async'; | 2071 import 'dart:async'; |
2446 f() async* { yield 42; } | 2072 f() async* { yield 42; } |
2447 dynamic f2() async* { yield 42; } | 2073 dynamic f2() async* { yield 42; } |
2448 Object f3() async* { yield 42; } | 2074 Object f3() async* { yield 42; } |
2449 Stream f4() async* { yield 42; } | 2075 Stream f4() async* { yield 42; } |
2450 Stream<dynamic> f5() async* { yield 42; } | 2076 Stream<dynamic> f5() async* { yield 42; } |
2451 Stream<Object> f6() async* { yield 42; } | 2077 Stream<Object> f6() async* { yield 42; } |
2452 Stream<num> f7() async* { yield 42; } | 2078 Stream<num> f7() async* { yield 42; } |
2453 Stream<int> f8() async* { yield 42; } | 2079 Stream<int> f8() async* { yield 42; } |
2454 ''', | 2080 ''', []); |
2455 []); | |
2456 } | 2081 } |
2457 | 2082 |
2458 test_legalAsyncReturnType_function_supertypeOfFuture() async { | 2083 test_legalAsyncReturnType_function_supertypeOfFuture() async { |
2459 await assertErrorsInCode( | 2084 await assertErrorsInCode(''' |
2460 ''' | |
2461 import 'dart:async'; | 2085 import 'dart:async'; |
2462 f() async { return 42; } | 2086 f() async { return 42; } |
2463 dynamic f2() async { return 42; } | 2087 dynamic f2() async { return 42; } |
2464 Object f3() async { return 42; } | 2088 Object f3() async { return 42; } |
2465 Future f4() async { return 42; } | 2089 Future f4() async { return 42; } |
2466 Future<dynamic> f5() async { return 42; } | 2090 Future<dynamic> f5() async { return 42; } |
2467 Future<Object> f6() async { return 42; } | 2091 Future<Object> f6() async { return 42; } |
2468 Future<num> f7() async { return 42; } | 2092 Future<num> f7() async { return 42; } |
2469 Future<int> f8() async { return 42; } | 2093 Future<int> f8() async { return 42; } |
2470 ''', | 2094 ''', []); |
2471 []); | |
2472 } | 2095 } |
2473 | 2096 |
2474 test_legalSyncGeneratorReturnType_function_supertypeOfIterable() async { | 2097 test_legalSyncGeneratorReturnType_function_supertypeOfIterable() async { |
2475 await assertErrorsInCode( | 2098 await assertErrorsInCode(''' |
2476 ''' | |
2477 f() sync* { yield 42; } | 2099 f() sync* { yield 42; } |
2478 dynamic f2() sync* { yield 42; } | 2100 dynamic f2() sync* { yield 42; } |
2479 Object f3() sync* { yield 42; } | 2101 Object f3() sync* { yield 42; } |
2480 Iterable f4() sync* { yield 42; } | 2102 Iterable f4() sync* { yield 42; } |
2481 Iterable<dynamic> f5() sync* { yield 42; } | 2103 Iterable<dynamic> f5() sync* { yield 42; } |
2482 Iterable<Object> f6() sync* { yield 42; } | 2104 Iterable<Object> f6() sync* { yield 42; } |
2483 Iterable<num> f7() sync* { yield 42; } | 2105 Iterable<num> f7() sync* { yield 42; } |
2484 Iterable<int> f8() sync* { yield 42; } | 2106 Iterable<int> f8() sync* { yield 42; } |
2485 ''', | 2107 ''', []); |
2486 []); | |
2487 } | 2108 } |
2488 } | 2109 } |
OLD | NEW |