| 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 /// Tests for type inference. | 5 /// Tests for type inference. |
| 6 library dev_compiler.test.inferred_type_test; | 6 library dev_compiler.test.inferred_type_test; |
| 7 | 7 |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 import 'package:dev_compiler/src/testing.dart'; | 10 import 'package:dev_compiler/src/testing.dart'; |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 580 |
| 581 test('infer types on loop indices', () { | 581 test('infer types on loop indices', () { |
| 582 // foreach loop | 582 // foreach loop |
| 583 testChecker({ | 583 testChecker({ |
| 584 '/main.dart': ''' | 584 '/main.dart': ''' |
| 585 class Foo { | 585 class Foo { |
| 586 int bar = 42; | 586 int bar = 42; |
| 587 } | 587 } |
| 588 | 588 |
| 589 test() { | 589 test() { |
| 590 var l = List<Foo>(); | 590 var list = <Foo>[]; |
| 591 for (var x in list) { | 591 for (var x in list) { |
| 592 String y = /*info:DynamicCast should be severe:StaticTypeError*/x; | 592 String y = /*severe:StaticTypeError*/x; |
| 593 } |
| 594 |
| 595 for (dynamic x in list) { |
| 596 String y = /*info:DynamicCast*/x; |
| 597 } |
| 598 |
| 599 for (String x in /*severe:StaticTypeError*/list) { |
| 600 String y = x; |
| 601 } |
| 602 |
| 603 var z; |
| 604 for(z in list) { |
| 605 String y = /*info:DynamicCast*/z; |
| 606 } |
| 607 |
| 608 Iterable iter = list; |
| 609 for (Foo x in /*warning:DownCastComposite*/iter) { |
| 610 var y = x; |
| 611 } |
| 612 |
| 613 dynamic iter2 = list; |
| 614 for (Foo x in /*warning:DownCastComposite*/iter2) { |
| 615 var y = x; |
| 616 } |
| 617 |
| 618 var map = <String, Foo>{}; |
| 619 // Error: map must be an Iterable. |
| 620 for (var x in /*severe:StaticTypeError*/map) { |
| 621 String y = /*info:DynamicCast*/x; |
| 622 } |
| 623 |
| 624 // We're not properly inferring that map.keys is an Iterable<String> |
| 625 // and that x is a String. |
| 626 for (var x in /*info:DynamicCast should be pass*/map.keys) { |
| 627 String y = /*info:DynamicCast should be pass*/x; |
| 593 } | 628 } |
| 594 } | 629 } |
| 595 ''' | 630 ''' |
| 596 }); | 631 }); |
| 597 | 632 |
| 598 // for loop, with inference | 633 // for loop, with inference |
| 599 testChecker({ | 634 testChecker({ |
| 600 '/main.dart': ''' | 635 '/main.dart': ''' |
| 601 test() { | 636 test() { |
| 602 for (var i = 0; i < 10; i++) { | 637 for (var i = 0; i < 10; i++) { |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 static final T foo = m1(m2(m3('', ''))); | 1208 static final T foo = m1(m2(m3('', ''))); |
| 1174 static T m1(String m) { return null; } | 1209 static T m1(String m) { return null; } |
| 1175 static String m2(e) { return ''; } | 1210 static String m2(e) { return ''; } |
| 1176 } | 1211 } |
| 1177 | 1212 |
| 1178 | 1213 |
| 1179 ''' | 1214 ''' |
| 1180 }, inferFromOverrides: true, inferTransitively: true); | 1215 }, inferFromOverrides: true, inferTransitively: true); |
| 1181 }); | 1216 }); |
| 1182 } | 1217 } |
| OLD | NEW |