Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: test/checker/inferred_type_test.dart

Issue 1048863003: Handle for-in loops (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/checker/resolver.dart ('k') | test/codegen/expect/server_mode/html_input.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « lib/src/checker/resolver.dart ('k') | test/codegen/expect/server_mode/html_input.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698