Chromium Code Reviews| 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 for (var x in /*severe:StaticTypeError*/map) { | |
|
Siggi Cherem (dart-lang)
2015/03/30 23:42:12
is this an error because the type is not iterable?
vsm
2015/03/31 00:24:47
Yes, a cast is needed and will fail here. Note, I
| |
| 620 String y = /*info:DynamicCast*/x; | |
| 593 } | 621 } |
| 594 } | 622 } |
| 595 ''' | 623 ''' |
| 596 }); | 624 }); |
| 597 | 625 |
| 598 // for loop, with inference | 626 // for loop, with inference |
| 599 testChecker({ | 627 testChecker({ |
| 600 '/main.dart': ''' | 628 '/main.dart': ''' |
| 601 test() { | 629 test() { |
| 602 for (var i = 0; i < 10; i++) { | 630 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('', ''))); | 1201 static final T foo = m1(m2(m3('', ''))); |
| 1174 static T m1(String m) { return null; } | 1202 static T m1(String m) { return null; } |
| 1175 static String m2(e) { return ''; } | 1203 static String m2(e) { return ''; } |
| 1176 } | 1204 } |
| 1177 | 1205 |
| 1178 | 1206 |
| 1179 ''' | 1207 ''' |
| 1180 }, inferFromOverrides: true, inferTransitively: true); | 1208 }, inferFromOverrides: true, inferTransitively: true); |
| 1181 }); | 1209 }); |
| 1182 } | 1210 } |
| OLD | NEW |