| 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 ddc.test.checker_test; | 6 library ddc.test.checker_test; |
| 7 | 7 |
| 8 import 'package:unittest/compact_vm_config.dart'; | 8 import 'package:unittest/compact_vm_config.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| (...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1476 l2 = /*warning:DownCastDynamic*/l1; | 1476 l2 = /*warning:DownCastDynamic*/l1; |
| 1477 | 1477 |
| 1478 l2 = /*warning:DownCastExact*/new List(); | 1478 l2 = /*warning:DownCastExact*/new List(); |
| 1479 l2 = /*warning:DownCastExact*/new List(10); | 1479 l2 = /*warning:DownCastExact*/new List(10); |
| 1480 l2 = /*warning:DownCastExact*/new List.filled(10, 42); | 1480 l2 = /*warning:DownCastExact*/new List.filled(10, 42); |
| 1481 } | 1481 } |
| 1482 ''' | 1482 ''' |
| 1483 }); | 1483 }); |
| 1484 }); | 1484 }); |
| 1485 | 1485 |
| 1486 test('Type checking literals', () { |
| 1487 testChecker({ |
| 1488 '/main.dart': ''' |
| 1489 test() { |
| 1490 num n = 3; |
| 1491 int i = 3; |
| 1492 String s = "hello"; |
| 1493 { |
| 1494 List<int> l = <int>[i]; |
| 1495 l = <int>[/*severe:StaticTypeError*/s]; |
| 1496 l = <int>[/*info:DownCast*/n]; |
| 1497 l = <int>[i, /*info:DownCast*/n, /*severe:StaticTypeError*/s]; |
| 1498 } |
| 1499 { |
| 1500 List l = [i]; |
| 1501 l = [s]; |
| 1502 l = [n]; |
| 1503 l = [i, n, s]; |
| 1504 } |
| 1505 { |
| 1506 Map<String, int> m = <String, int>{s: i}; |
| 1507 m = <String, int>{s: /*severe:StaticTypeError*/s}; |
| 1508 m = <String, int>{s: /*info:DownCast*/n}; |
| 1509 m = <String, int>{s: i, |
| 1510 s: /*info:DownCast*/n, |
| 1511 s: /*severe:StaticTypeError*/s}; |
| 1512 } |
| 1513 // TODO(leafp): We can't currently test for key errors since the |
| 1514 // error marker binds to the entire entry. |
| 1515 { |
| 1516 Map m = {s: i}; |
| 1517 m = {s: s}; |
| 1518 m = {s: n}; |
| 1519 m = {s: i, |
| 1520 s: n, |
| 1521 s: s}; |
| 1522 m = {i: s, |
| 1523 n: s, |
| 1524 s: s}; |
| 1525 } |
| 1526 } |
| 1527 ''' |
| 1528 }); |
| 1529 }); |
| 1530 |
| 1531 test('casts in constant contexts', () { |
| 1532 String mk(String error) => ''' |
| 1533 class A { |
| 1534 static const num n = 3.0; |
| 1535 static const int i = /*$error*/n; |
| 1536 final int fi; |
| 1537 const A(num a) : this.fi = /*$error*/a; |
| 1538 } |
| 1539 class B extends A { |
| 1540 const B(Object a) : super(/*$error*/a); |
| 1541 } |
| 1542 void foo(Object o) { |
| 1543 var a = const A(/*$error*/o); |
| 1544 } |
| 1545 '''; |
| 1546 testChecker({'/main.dart': mk("severe:StaticTypeError")}, |
| 1547 allowConstCasts: false); |
| 1548 testChecker({'/main.dart': mk("info:DownCast")}, allowConstCasts: true); |
| 1549 }); |
| 1550 |
| 1486 test('redirecting constructor', () { | 1551 test('redirecting constructor', () { |
| 1487 testChecker({ | 1552 testChecker({ |
| 1488 '/main.dart': ''' | 1553 '/main.dart': ''' |
| 1489 class A { | 1554 class A { |
| 1490 A(A x) {} | 1555 A(A x) {} |
| 1491 A.two() : this(/*severe:StaticTypeError*/3); | 1556 A.two() : this(/*severe:StaticTypeError*/3); |
| 1492 } | 1557 } |
| 1493 ''' | 1558 ''' |
| 1494 }); | 1559 }); |
| 1495 }); | 1560 }); |
| (...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2639 '/main.dart': ''' | 2704 '/main.dart': ''' |
| 2640 class A {} | 2705 class A {} |
| 2641 class T1 implements A { | 2706 class T1 implements A { |
| 2642 /*severe:InferableOverride*/toString() {} | 2707 /*severe:InferableOverride*/toString() {} |
| 2643 } | 2708 } |
| 2644 ''' | 2709 ''' |
| 2645 }, inferFromOverrides: false); | 2710 }, inferFromOverrides: false); |
| 2646 }); | 2711 }); |
| 2647 }); | 2712 }); |
| 2648 } | 2713 } |
| OLD | NEW |