OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.task.strong.checker_test; | 5 library analyzer.test.src.task.strong.checker_test; |
6 | 6 |
7 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 7 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
8 | 8 |
9 import 'strong_test_helper.dart'; | 9 import 'strong_test_helper.dart'; |
10 | 10 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 } | 258 } |
259 | 259 |
260 class B { | 260 class B { |
261 A operator -(B b) => null; | 261 A operator -(B b) => null; |
262 } | 262 } |
263 | 263 |
264 class D { | 264 class D { |
265 D operator +(D d) => null; | 265 D operator +(D d) => null; |
266 } | 266 } |
267 | 267 |
| 268 class SubA extends A {} |
| 269 class SubSubA extends SubA {} |
| 270 |
268 foo() => new A(); | 271 foo() => new A(); |
269 | 272 |
270 test() { | 273 test() { |
271 int x = 0; | 274 int x = 0; |
272 x += 5; | 275 x += 5; |
273 /*error:STATIC_TYPE_ERROR*/x += /*error:INVALID_ASSIGNMENT*/3.14; | 276 x += /*error:INVALID_ASSIGNMENT*/3.14; |
274 | 277 |
275 double y = 0.0; | 278 double y = 0.0; |
276 y += 5; | 279 y += 5; |
277 y += 3.14; | 280 y += 3.14; |
278 | 281 |
279 num z = 0; | 282 num z = 0; |
280 z += 5; | 283 z += 5; |
281 z += 3.14; | 284 z += 3.14; |
282 | 285 |
283 x = /*info:DOWN_CAST_IMPLICIT*/x + z; | 286 x = /*info:DOWN_CAST_IMPLICIT*/x + z; |
284 x += /*info:DOWN_CAST_IMPLICIT*/z; | 287 /*info:DOWN_CAST_IMPLICIT_ASSIGN*/x += z; |
285 y = y + z; | 288 y = y + z; |
286 y += z; | 289 y += z; |
287 | 290 |
288 dynamic w = 42; | 291 dynamic w = 42; |
289 x += /*info:DYNAMIC_CAST*/w; | 292 /*info:DOWN_CAST_IMPLICIT_ASSIGN*/x += /*info:DYNAMIC_CAST*/w; |
290 y += /*info:DYNAMIC_CAST*/w; | 293 y += /*info:DYNAMIC_CAST*/w; |
291 z += /*info:DYNAMIC_CAST*/w; | 294 z += /*info:DYNAMIC_CAST*/w; |
292 | 295 |
293 A a = new A(); | 296 A a = new A(); |
294 B b = new B(); | 297 B b = new B(); |
295 var c = foo(); | 298 var c = foo(); |
296 a = a * b; | 299 a = a * b; |
297 a *= b; | 300 a *= b; |
298 a *= /*info:DYNAMIC_CAST*/c; | 301 a *= /*info:DYNAMIC_CAST*/c; |
299 a /= b; | 302 a /= b; |
300 a ~/= b; | 303 a ~/= b; |
301 a %= b; | 304 a %= b; |
302 a += b; | 305 a += b; |
303 a += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/a; | 306 a += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/a; |
304 a -= b; | 307 a -= b; |
305 /*error:STATIC_TYPE_ERROR*/b -= /*error:INVALID_ASSIGNMENT*/b; | 308 b -= /*error:INVALID_ASSIGNMENT*/b; |
306 a <<= b; | 309 a <<= b; |
307 a >>= b; | 310 a >>= b; |
308 a &= b; | 311 a &= b; |
309 a ^= b; | 312 a ^= b; |
310 a |= b; | 313 a |= b; |
311 /*info:DYNAMIC_INVOKE*/c += b; | 314 /*info:DYNAMIC_INVOKE*/c += b; |
312 | 315 |
| 316 SubA sa; |
| 317 /*info:DOWN_CAST_IMPLICIT_ASSIGN*/sa += b; |
| 318 SubSubA ssa = /*info:ASSIGNMENT_CAST,info:DOWN_CAST_IMPLICIT_ASSIGN*/sa += b; |
| 319 |
313 var d = new D(); | 320 var d = new D(); |
314 a[b] += d; | 321 a[b] += d; |
315 a[/*info:DYNAMIC_CAST*/c] += d; | 322 a[/*info:DYNAMIC_CAST*/c] += d; |
316 a[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z] += d; | 323 a[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z] += d; |
317 a[b] += /*info:DYNAMIC_CAST*/c; | 324 a[b] += /*info:DYNAMIC_CAST*/c; |
318 a[b] += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z; | 325 a[b] += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z; |
319 /*info:DYNAMIC_INVOKE,info:DYNAMIC_INVOKE*/c[b] += d; | 326 /*info:DYNAMIC_INVOKE,info:DYNAMIC_INVOKE*/c[b] += d; |
320 } | 327 } |
321 '''); | 328 '''); |
322 } | 329 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 final List<Q> list = /*info:INFERRED_TYPE_LITERAL*/const []; | 373 final List<Q> list = /*info:INFERRED_TYPE_LITERAL*/const []; |
367 final Map<Q, Iterable<Q>> m = /*info:INFERRED_TYPE_LITERAL*/const {}; | 374 final Map<Q, Iterable<Q>> m = /*info:INFERRED_TYPE_LITERAL*/const {}; |
368 const C(); | 375 const C(); |
369 } | 376 } |
370 main() { | 377 main() { |
371 const SetEquality<String>(); | 378 const SetEquality<String>(); |
372 } | 379 } |
373 '''); | 380 '''); |
374 } | 381 } |
375 | 382 |
| 383 void test_compoundAssignment_returnsDynamic() { |
| 384 checkFile(r''' |
| 385 class Foo { |
| 386 operator +(other) => null; |
| 387 } |
| 388 |
| 389 main() { |
| 390 var foo = new Foo(); |
| 391 foo = /*info:DYNAMIC_CAST*/foo + 1; |
| 392 /*info:DYNAMIC_CAST*/foo += 1; |
| 393 } |
| 394 '''); |
| 395 } |
| 396 |
376 void test_constructorInvalid() { | 397 void test_constructorInvalid() { |
377 // Regression test for https://github.com/dart-lang/sdk/issues/26695 | 398 // Regression test for https://github.com/dart-lang/sdk/issues/26695 |
378 checkFile(''' | 399 checkFile(''' |
379 class A { | 400 class A { |
380 B({ /*error:FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR*/this.test: 1.0 }) {} | 401 B({ /*error:FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR*/this.test: 1.0 }) {} |
381 final double test = 0.0; | 402 final double test = 0.0; |
382 } | 403 } |
383 '''); | 404 '''); |
384 } | 405 } |
385 | 406 |
(...skipping 3452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3838 } | 3859 } |
3839 | 3860 |
3840 void test_unaryOperators() { | 3861 void test_unaryOperators() { |
3841 checkFile(''' | 3862 checkFile(''' |
3842 class A { | 3863 class A { |
3843 A operator ~() => null; | 3864 A operator ~() => null; |
3844 A operator +(int x) => null; | 3865 A operator +(int x) => null; |
3845 A operator -(int x) => null; | 3866 A operator -(int x) => null; |
3846 A operator -() => null; | 3867 A operator -() => null; |
3847 } | 3868 } |
| 3869 class B extends A {} |
| 3870 class C extends B {} |
3848 | 3871 |
3849 foo() => new A(); | 3872 foo() => new A(); |
3850 | 3873 |
3851 test() { | 3874 test() { |
3852 A a = new A(); | 3875 A a = new A(); |
| 3876 B b = new B(); |
3853 var c = foo(); | 3877 var c = foo(); |
3854 dynamic d; | 3878 dynamic d; |
3855 | 3879 |
3856 ~a; | 3880 ~a; |
3857 (/*info:DYNAMIC_INVOKE*/~d); | 3881 (/*info:DYNAMIC_INVOKE*/~d); |
3858 | 3882 |
3859 !/*error:NON_BOOL_NEGATION_EXPRESSION*/a; | 3883 !/*error:NON_BOOL_NEGATION_EXPRESSION*/a; |
3860 !/*info:DYNAMIC_CAST*/d; | 3884 !/*info:DYNAMIC_CAST*/d; |
3861 | 3885 |
3862 -a; | 3886 -a; |
3863 (/*info:DYNAMIC_INVOKE*/-d); | 3887 (/*info:DYNAMIC_INVOKE*/-d); |
3864 | 3888 |
3865 ++a; | 3889 ++a; |
3866 --a; | 3890 --a; |
3867 (/*info:DYNAMIC_INVOKE*/++d); | 3891 (/*info:DYNAMIC_INVOKE*/++d); |
3868 (/*info:DYNAMIC_INVOKE*/--d); | 3892 (/*info:DYNAMIC_INVOKE*/--d); |
3869 | 3893 |
3870 a++; | 3894 a++; |
3871 a--; | 3895 a--; |
3872 (/*info:DYNAMIC_INVOKE*/d++); | 3896 (/*info:DYNAMIC_INVOKE*/d++); |
3873 (/*info:DYNAMIC_INVOKE*/d--); | 3897 (/*info:DYNAMIC_INVOKE*/d--); |
| 3898 |
| 3899 ++/*info:DOWN_CAST_IMPLICIT_ASSIGN*/b; |
| 3900 --/*info:DOWN_CAST_IMPLICIT_ASSIGN*/b; |
| 3901 /*info:DOWN_CAST_IMPLICIT_ASSIGN*/b++; |
| 3902 /*info:DOWN_CAST_IMPLICIT_ASSIGN*/b--; |
| 3903 |
| 3904 takesC(C c) => null; |
| 3905 takesC(/*info:DOWN_CAST_IMPLICIT*/++/*info:DOWN_CAST_IMPLICIT_ASSIGN*/b); |
| 3906 takesC(/*info:DOWN_CAST_IMPLICIT*/--/*info:DOWN_CAST_IMPLICIT_ASSIGN*/b); |
| 3907 takesC(/*info:DOWN_CAST_IMPLICIT,info:DOWN_CAST_IMPLICIT_ASSIGN*/b++); |
| 3908 takesC(/*info:DOWN_CAST_IMPLICIT,info:DOWN_CAST_IMPLICIT_ASSIGN*/b--); |
3874 }'''); | 3909 }'''); |
3875 } | 3910 } |
3876 | 3911 |
3877 void test_unboundRedirectingConstructor() { | 3912 void test_unboundRedirectingConstructor() { |
3878 // This is a regression test for https://github.com/dart-lang/sdk/issues/250
71 | 3913 // This is a regression test for https://github.com/dart-lang/sdk/issues/250
71 |
3879 checkFile(''' | 3914 checkFile(''' |
3880 class Foo { | 3915 class Foo { |
3881 Foo() : /*error:REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR*/this.init(); | 3916 Foo() : /*error:REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR*/this.init(); |
3882 } | 3917 } |
3883 '''); | 3918 '''); |
(...skipping 30 matching lines...) Expand all Loading... |
3914 void _addMetaLibrary() { | 3949 void _addMetaLibrary() { |
3915 addFile(r''' | 3950 addFile(r''' |
3916 library meta; | 3951 library meta; |
3917 class _Checked { const _Checked(); } | 3952 class _Checked { const _Checked(); } |
3918 const Object checked = const _Checked(); | 3953 const Object checked = const _Checked(); |
3919 | 3954 |
3920 class _Virtual { const _Virtual(); } | 3955 class _Virtual { const _Virtual(); } |
3921 const Object virtual = const _Virtual(); | 3956 const Object virtual = const _Virtual(); |
3922 ''', name: '/meta.dart'); | 3957 ''', name: '/meta.dart'); |
3923 } | 3958 } |
OLD | NEW |