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