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

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

Issue 1396993002: housecleaning: remove nonnullableTypes (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 2 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 /// General type checking tests 5 /// General type checking tests
6 library dev_compiler.test.checker_test; 6 library dev_compiler.test.checker_test;
7 7
8 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
9 9
10 import '../testing.dart'; 10 import '../testing.dart';
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 var toStringClosure2 = helper.toString; 200 var toStringClosure2 = helper.toString;
201 (/*info:DynamicInvoke*/toStringClosure2()); 201 (/*info:DynamicInvoke*/toStringClosure2());
202 int hashCode = /*info:DynamicCast*/helper.hashCode; 202 int hashCode = /*info:DynamicCast*/helper.hashCode;
203 203
204 baz().toString(); 204 baz().toString();
205 baz().hashCode; 205 baz().hashCode;
206 } 206 }
207 ''' 207 '''
208 }); 208 });
209 209
210 testChecker('Primitives', {
211 '/main.dart': '''
212 int /*severe:InvalidVariableDeclaration*/a;
213 double /*severe:InvalidVariableDeclaration*/b;
214 num c;
215
216 class A {
217 int a;
218 double b;
219 num c;
220
221 static int /*severe:InvalidVariableDeclaration*/x;
222 static double /*severe:InvalidVariableDeclaration*/y;
223 static num z;
224 }
225
226 void foo(int w, [int x = /*severe:StaticTypeError*/null, int /*severe:In validVariableDeclaration*/y, int z = 0]) {
227 }
228
229 void bar(int w, {int x = /*severe:StaticTypeError*/null, int /*severe:In validVariableDeclaration*/y, int z: 0}) {
230 }
231
232 void main() {
233 int /*severe:InvalidVariableDeclaration*/x;
234 double /*severe:InvalidVariableDeclaration*/y;
235 num z;
236 bool b;
237
238 // int is non-nullable
239 x = /*severe:StaticTypeError*/null;
240 x = 42;
241 x = /*info:DownCastImplicit*/z;
242
243 // double is non-nullable
244 y = /*severe:StaticTypeError*/null;
245 y = /*severe:StaticTypeError*/42;
246 y = 42.0;
247 y = /*info:DownCastImplicit*/z;
248
249 // num is nullable
250 z = null;
251 z = x;
252 z = y;
253
254 // bool is nullable
255 b = null;
256 b = true;
257 }
258 '''
259 }, nonnullableTypes: <String>[
260 'int',
261 'double'
262 ]);
263
264 testChecker('Primitives and generics', {
265 '/main.dart': '''
266 class A<T> {
267 // TODO(vsm): This needs a static info indicating a runtime
268 // check at construction.
269 T x;
270
271 // TODO(vsm): Should this be a different type of DownCast?
272 T foo() => /*info:DownCastImplicit*/null;
273
274 void bar() {
275 int /*severe:InvalidVariableDeclaration*/x;
276 num y;
277 // TODO(vsm): This should be a runtime check:
278 // Transformed to: T z = cast(null, T)
279 T /*severe:InvalidVariableDeclaration*/z;
280 }
281
282 void baz(T x, [T /*severe:InvalidVariableDeclaration*/y, T z = /*info: DownCastImplicit*/null]) {
283 }
284 }
285
286 class B<T extends List> {
287 T x;
288
289 // T cannot be primitive.
290 T foo() => null;
291 }
292
293 class C<T extends num> {
294 // TODO(vsm): This needs a static info indicating a runtime
295 // check at construction.
296 T x;
297
298 // TODO(vsm): Should this be a different type of DownCast?
299 T foo() => /*info:DownCastImplicit*/null;
300 }
301 '''
302 }, nonnullableTypes: <String>[
303 'int',
304 'double'
305 ]);
306
307 testChecker('Constructors', { 210 testChecker('Constructors', {
308 '/main.dart': ''' 211 '/main.dart': '''
309 const num z = 25; 212 const num z = 25;
310 Object obj = "world"; 213 Object obj = "world";
311 214
312 class A { 215 class A {
313 int x; 216 int x;
314 String y; 217 String y;
315 218
316 A(this.x) : this.y = /*severe:StaticTypeError*/42; 219 A(this.x) : this.y = /*severe:StaticTypeError*/42;
(...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after
2552 2455
2553 baz1() sync* { yield* (/*info:DynamicCast*/x); } 2456 baz1() sync* { yield* (/*info:DynamicCast*/x); }
2554 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } 2457 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); }
2555 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } 2458 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); }
2556 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } 2459 Iterable<int> baz4() sync* { yield* new Iterable<int>(); }
2557 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new Iterable()); } 2460 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new Iterable()); }
2558 ''' 2461 '''
2559 }); 2462 });
2560 }); 2463 });
2561 } 2464 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698