| 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 /// General type checking tests | 5 /// General type checking tests |
| 6 library dev_compiler.test.checker_test; | 6 library dev_compiler.test.checker_test; |
| 7 | 7 |
| 8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
| 9 | 9 |
| 10 import '../testing.dart'; | 10 import '../testing.dart'; |
| (...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 /*severe:InvalidMethodOverride*/A f1; // invalid for getter | 1365 /*severe:InvalidMethodOverride*/A f1; // invalid for getter |
| 1366 /*severe:InvalidMethodOverride*/C f2; // invalid for setter | 1366 /*severe:InvalidMethodOverride*/C f2; // invalid for setter |
| 1367 var f3; | 1367 var f3; |
| 1368 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic
f4; | 1368 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic
f4; |
| 1369 } | 1369 } |
| 1370 ''' | 1370 ''' |
| 1371 }, | 1371 }, |
| 1372 inferFromOverrides: true); | 1372 inferFromOverrides: true); |
| 1373 | 1373 |
| 1374 testChecker( | 1374 testChecker( |
| 1375 'field/field override 2', | |
| 1376 { | |
| 1377 '/main.dart': ''' | |
| 1378 class A {} | |
| 1379 class B extends A {} | |
| 1380 class C extends B {} | |
| 1381 | |
| 1382 class Base { | |
| 1383 B f1; | |
| 1384 B f2; | |
| 1385 B f3; | |
| 1386 B f4; | |
| 1387 } | |
| 1388 | |
| 1389 class Child extends Base { | |
| 1390 /*severe:InvalidMethodOverride*/A f1; // invalid for getter | |
| 1391 /*severe:InvalidMethodOverride*/C f2; // invalid for setter | |
| 1392 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/var f3; | |
| 1393 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic
f4; | |
| 1394 } | |
| 1395 ''' | |
| 1396 }, | |
| 1397 inferFromOverrides: false); | |
| 1398 | |
| 1399 testChecker( | |
| 1400 'getter/getter override', | 1375 'getter/getter override', |
| 1401 { | 1376 { |
| 1402 '/main.dart': ''' | 1377 '/main.dart': ''' |
| 1403 class A {} | 1378 class A {} |
| 1404 class B extends A {} | 1379 class B extends A {} |
| 1405 class C extends B {} | 1380 class C extends B {} |
| 1406 | 1381 |
| 1407 abstract class Base { | 1382 abstract class Base { |
| 1408 B get f1; | 1383 B get f1; |
| 1409 B get f2; | 1384 B get f2; |
| 1410 B get f3; | 1385 B get f3; |
| 1411 B get f4; | 1386 B get f4; |
| 1412 } | 1387 } |
| 1413 | 1388 |
| 1414 class Child extends Base { | 1389 class Child extends Base { |
| 1415 /*severe:InvalidMethodOverride*/A get f1 => null; | 1390 /*severe:InvalidMethodOverride*/A get f1 => null; |
| 1416 C get f2 => null; | 1391 C get f2 => null; |
| 1417 get f3 => null; | 1392 get f3 => null; |
| 1418 /*severe:InvalidMethodOverride*/dynamic get f4 => null; | 1393 /*severe:InvalidMethodOverride*/dynamic get f4 => null; |
| 1419 } | 1394 } |
| 1420 ''' | 1395 ''' |
| 1421 }, | 1396 }, |
| 1422 inferFromOverrides: true); | 1397 inferFromOverrides: true); |
| 1423 | 1398 |
| 1424 testChecker( | 1399 testChecker( |
| 1425 'getter/getter override 2', | |
| 1426 { | |
| 1427 '/main.dart': ''' | |
| 1428 class A {} | |
| 1429 class B extends A {} | |
| 1430 class C extends B {} | |
| 1431 | |
| 1432 abstract class Base { | |
| 1433 B get f1; | |
| 1434 B get f2; | |
| 1435 B get f3; | |
| 1436 B get f4; | |
| 1437 } | |
| 1438 | |
| 1439 class Child extends Base { | |
| 1440 /*severe:InvalidMethodOverride*/A get f1 => null; | |
| 1441 C get f2 => null; | |
| 1442 /*severe:InvalidMethodOverride*/get f3 => null; | |
| 1443 /*severe:InvalidMethodOverride*/dynamic get f4 => null; | |
| 1444 } | |
| 1445 ''' | |
| 1446 }, | |
| 1447 inferFromOverrides: false); | |
| 1448 | |
| 1449 testChecker( | |
| 1450 'field/getter override', | 1400 'field/getter override', |
| 1451 { | 1401 { |
| 1452 '/main.dart': ''' | 1402 '/main.dart': ''' |
| 1453 class A {} | 1403 class A {} |
| 1454 class B extends A {} | 1404 class B extends A {} |
| 1455 class C extends B {} | 1405 class C extends B {} |
| 1456 | 1406 |
| 1457 abstract class Base { | 1407 abstract class Base { |
| 1458 B f1; | 1408 B f1; |
| 1459 B f2; | 1409 B f2; |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2018 } | 1968 } |
| 2019 | 1969 |
| 2020 class I1 { | 1970 class I1 { |
| 2021 m(B a) {} | 1971 m(B a) {} |
| 2022 } | 1972 } |
| 2023 | 1973 |
| 2024 class T1 /*severe:InvalidMethodOverride*/extends Base | 1974 class T1 /*severe:InvalidMethodOverride*/extends Base |
| 2025 implements I1 {} | 1975 implements I1 {} |
| 2026 | 1976 |
| 2027 class T2 extends Base implements I1 { | 1977 class T2 extends Base implements I1 { |
| 2028 /*severe:InvalidMethodOverride*/m(a) {} | 1978 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a
) {} |
| 2029 } | 1979 } |
| 2030 | 1980 |
| 2031 class T3 extends Object with /*severe:InvalidMethodOverride*/Base | 1981 class T3 extends Object with /*severe:InvalidMethodOverride*/Base |
| 2032 implements I1 {} | 1982 implements I1 {} |
| 2033 | 1983 |
| 2034 class T4 extends Object with Base implements I1 { | 1984 class T4 extends Object with Base implements I1 { |
| 2035 /*severe:InvalidMethodOverride*/m(a) {} | 1985 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a
) {} |
| 2036 } | 1986 } |
| 2037 ''' | 1987 ''' |
| 2038 }); | 1988 }); |
| 2039 }); | 1989 }); |
| 2040 | 1990 |
| 2041 group('class override of grand interface', () { | 1991 group('class override of grand interface', () { |
| 2042 testChecker('interface of interface of child', { | 1992 testChecker('interface of interface of child', { |
| 2043 '/main.dart': ''' | 1993 '/main.dart': ''' |
| 2044 class A {} | 1994 class A {} |
| 2045 class B {} | 1995 class B {} |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2472 // different. | 2422 // different. |
| 2473 // TODO(sigmund): should we merge these as well? | 2423 // TODO(sigmund): should we merge these as well? |
| 2474 class T1 /*severe:InvalidMethodOverride*/extends Base | 2424 class T1 /*severe:InvalidMethodOverride*/extends Base |
| 2475 with /*severe:InvalidMethodOverride*/M | 2425 with /*severe:InvalidMethodOverride*/M |
| 2476 implements I1 { | 2426 implements I1 { |
| 2477 } | 2427 } |
| 2478 ''' | 2428 ''' |
| 2479 }); | 2429 }); |
| 2480 }); | 2430 }); |
| 2481 | 2431 |
| 2482 // This is a regression test: we used to report it twice because it was | |
| 2483 // the top super class and top super interface. | |
| 2484 // TODO(sigmund): maybe we generalize this and don't report again errors | |
| 2485 // when an interface is also a superclass. | |
| 2486 testChecker( | |
| 2487 'no reporting of overrides with Object twice.', | |
| 2488 { | |
| 2489 '/main.dart': ''' | |
| 2490 class A {} | |
| 2491 class T1 implements A { | |
| 2492 /*severe:InvalidMethodOverride*/toString() {} | |
| 2493 } | |
| 2494 ''' | |
| 2495 }, | |
| 2496 inferFromOverrides: false); | |
| 2497 | |
| 2498 testChecker('invalid runtime checks', { | 2432 testChecker('invalid runtime checks', { |
| 2499 '/main.dart': ''' | 2433 '/main.dart': ''' |
| 2500 typedef int I2I(int x); | 2434 typedef int I2I(int x); |
| 2501 typedef int D2I(x); | 2435 typedef int D2I(x); |
| 2502 typedef int II2I(int x, int y); | 2436 typedef int II2I(int x, int y); |
| 2503 typedef int DI2I(x, int y); | 2437 typedef int DI2I(x, int y); |
| 2504 typedef int ID2I(int x, y); | 2438 typedef int ID2I(int x, y); |
| 2505 typedef int DD2I(x, y); | 2439 typedef int DD2I(x, y); |
| 2506 | 2440 |
| 2507 typedef I2D(int x); | 2441 typedef I2D(int x); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2630 | 2564 |
| 2631 baz1() sync* { yield* (/*info:DynamicCast*/x); } | 2565 baz1() sync* { yield* (/*info:DynamicCast*/x); } |
| 2632 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } | 2566 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } |
| 2633 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } | 2567 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } |
| 2634 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } | 2568 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } |
| 2635 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new
Iterable()); } | 2569 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new
Iterable()); } |
| 2636 ''' | 2570 ''' |
| 2637 }); | 2571 }); |
| 2638 }); | 2572 }); |
| 2639 } | 2573 } |
| OLD | NEW |