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

Side by Side Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 1823793002: Better casting of for-in loops. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
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 // TODO(jmesserly): this file needs to be refactored, it's a port from 5 // TODO(jmesserly): this file needs to be refactored, it's a port from
6 // package:dev_compiler's tests 6 // package:dev_compiler's tests
7 /// General type checking tests 7 /// General type checking tests
8 library analyzer.test.src.task.strong.checker_test; 8 library analyzer.test.src.task.strong.checker_test;
9 9
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 do {} while (/*warning:NON_BOOL_CONDITION*/i); 80 do {} while (/*warning:NON_BOOL_CONDITION*/i);
81 81
82 for (;b;) {} 82 for (;b;) {}
83 for (;/*info:DYNAMIC_CAST*/dyn;) {} 83 for (;/*info:DYNAMIC_CAST*/dyn;) {}
84 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} 84 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {}
85 for (;/*warning:NON_BOOL_CONDITION*/i;) {} 85 for (;/*warning:NON_BOOL_CONDITION*/i;) {}
86 } 86 }
87 '''); 87 ''');
88 }); 88 });
89 89
90 test('for-in casts iterable element to variable', () {
91 checkFile('''
92 main() {
93 // Don't choke if sequence is not iterable.
94 for (var i in /*warning:FOR_IN_OF_INVALID_TYPE*/1234) {}
95
96 // Dynamic cast.
97 for (String /*info:DYNAMIC_CAST*/s in <dynamic>[]) {}
98
99 // Identity cast.
100 for (String s in <String>[]) {}
101
102 // Untyped.
103 for (var s in <String>[]) {}
104
105 // Downcast.
106 for (int /*info:DOWN_CAST_IMPLICIT*/i in <num>[]) {}
vsm 2016/03/21 21:25:20 nice!
Bob Nystrom 2016/03/21 22:44:55 \o/
107 }
108 ''');
109 });
110
111 test('await for-in casts stream element to variable', () {
112 checkFile('''
113 import 'dart:async';
114 main() async {
115 // Don't choke if sequence is not stream.
116 await for (var i in /*warning:FOR_IN_OF_INVALID_TYPE*/1234) {}
117
118 // Dynamic cast.
119 await for (String /*info:DYNAMIC_CAST*/s in new Stream<dynamic>()) {}
120
121 // Identity cast.
122 await for (String s in new Stream<String>()) {}
123
124 // Untyped.
125 await for (var s in new Stream<String>()) {}
126
127 // Downcast.
128 await for (int /*info:DOWN_CAST_IMPLICIT*/i in new Stream<num>()) {}
129 }
130 ''');
131 });
132
90 test('dynamic invocation', () { 133 test('dynamic invocation', () {
91 checkFile(''' 134 checkFile('''
92 class A { 135 class A {
93 dynamic call(dynamic x) => x; 136 dynamic call(dynamic x) => x;
94 } 137 }
95 class B extends A { 138 class B extends A {
96 int call(int x) => x; 139 int call(int x) => x;
97 double col(double x) => x; 140 double col(double x) => x;
98 } 141 }
99 void main() { 142 void main() {
(...skipping 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after
2906 2949
2907 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; } 2950 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; }
2908 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; } 2951 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; }
2909 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; } 2952 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; }
2910 Iterable<int> baz4() sync* { yield* bar3(); } 2953 Iterable<int> baz4() sync* { yield* bar3(); }
2911 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new List(); } 2954 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new List(); }
2912 '''); 2955 ''');
2913 }); 2956 });
2914 }); 2957 });
2915 } 2958 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698