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

Side by Side Diff: tests/compiler/dart2js/subtype_test.dart

Issue 12334070: Support runtime check of function types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fix Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library subtype_test; 5 library subtype_test;
6 6
7 import 'package:expect/expect.dart'; 7 import 'package:expect/expect.dart';
8 import 'type_test_helper.dart'; 8 import 'type_test_helper.dart';
9 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; 9 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart';
10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t" 10 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 expect(true, A, function); 257 expect(true, A, function);
258 expect(true, A, m1); 258 expect(true, A, m1);
259 expect(true, A, m2); 259 expect(true, A, m2);
260 expect(false, A, m3); 260 expect(false, A, m3);
261 expect(false, A, m4); 261 expect(false, A, m4);
262 expect(true, A, m5); 262 expect(true, A, m5);
263 } 263 }
264 264
265 testFunctionSubtyping() { 265 testFunctionSubtyping() {
266 var env = new TypeEnvironment(r""" 266 var env = new TypeEnvironment(r"""
267 _() => null;
267 void void_() {} 268 void void_() {}
268 void void_2() {} 269 void void_2() {}
269 int int_() => 0; 270 int int_() => 0;
270 int int_2() => 0; 271 int int_2() => 0;
271 Object Object_() => null; 272 Object Object_() => null;
272 double double_() => 0.0; 273 double double_() => 0.0;
273 void void__int(int i) {} 274 void void__int(int i) {}
274 int int__int(int i) => 0; 275 int int__int(int i) => 0;
275 int int__int2(int i) => 0; 276 int int__int2(int i) => 0;
276 int int__Object(Object o) => 0; 277 int int__Object(Object o) => 0;
277 Object Object__int(int i) => null; 278 Object Object__int(int i) => null;
278 int int__double(double d) => 0; 279 int int__double(double d) => 0;
279 int int__int_int(int i1, int i2) => 0; 280 int int__int_int(int i1, int i2) => 0;
280 void inline_void_(void f()) {} 281 void inline_void_(void f()) {}
281 void inline_void__int(void f(int i)) {} 282 void inline_void__int(void f(int i)) {}
282 """); 283 """);
283 functionSubtypingHelper(env); 284 functionSubtypingHelper(env);
284 } 285 }
285 286
286 testTypedefSubtyping() { 287 testTypedefSubtyping() {
287 var env = new TypeEnvironment(r""" 288 var env = new TypeEnvironment(r"""
289 typedef _();
288 typedef void void_(); 290 typedef void void_();
289 typedef void void_2(); 291 typedef void void_2();
290 typedef int int_(); 292 typedef int int_();
291 typedef int int_2(); 293 typedef int int_2();
292 typedef Object Object_(); 294 typedef Object Object_();
293 typedef double double_(); 295 typedef double double_();
294 typedef void void__int(int i); 296 typedef void void__int(int i);
295 typedef int int__int(int i); 297 typedef int int__int(int i);
296 typedef int int__int2(int i); 298 typedef int int__int2(int i);
297 typedef int int__Object(Object o); 299 typedef int int__Object(Object o);
(...skipping 12 matching lines...) Expand all
310 DartType supertype = env.getElementType(sup); 312 DartType supertype = env.getElementType(sup);
311 Expect.equals(expectedResult, env.isSubtype(subtype, supertype), 313 Expect.equals(expectedResult, env.isSubtype(subtype, supertype),
312 '$subtype <: $supertype'); 314 '$subtype <: $supertype');
313 } 315 }
314 316
315 // () -> int <: Function 317 // () -> int <: Function
316 expect(true, 'int_', 'Function'); 318 expect(true, 'int_', 'Function');
317 // Function <: () -> int 319 // Function <: () -> int
318 expect(false, 'Function', 'int_'); 320 expect(false, 'Function', 'int_');
319 321
322 // () -> dynamic <: () -> dynamic
323 expect(true, '_', '_');
324 // () -> dynamic <: () -> void
325 expect(true, '_', 'void_');
326 // () -> void <: () -> dynamic
327 expect(true, 'void_', '_');
328
320 // () -> int <: () -> void 329 // () -> int <: () -> void
321 expect(true, 'int_', 'void_'); 330 expect(true, 'int_', 'void_');
322 // () -> void <: () -> int 331 // () -> void <: () -> int
323 expect(false, 'void_', 'int_'); 332 expect(false, 'void_', 'int_');
324 // () -> void <: () -> void 333 // () -> void <: () -> void
325 expect(true, 'void_', 'void_2'); 334 expect(true, 'void_', 'void_2');
326 // () -> int <: () -> int 335 // () -> int <: () -> int
327 expect(true, 'int_', 'int_2'); 336 expect(true, 'int_', 'int_2');
328 // () -> int <: () -> Object 337 // () -> int <: () -> Object
329 expect(true, 'int_', 'Object_'); 338 expect(true, 'int_', 'Object_');
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 expect(true, J_U, Object_); 729 expect(true, J_U, Object_);
721 expect(false, J_U, num_); 730 expect(false, J_U, num_);
722 expect(false, J_U, int_); 731 expect(false, J_U, int_);
723 expect(false, J_U, String_); 732 expect(false, J_U, String_);
724 expect(true, J_U, dynamic_); 733 expect(true, J_U, dynamic_);
725 expect(false, J_U, J_T); 734 expect(false, J_U, J_T);
726 expect(true, J_U, J_S); 735 expect(true, J_U, J_S);
727 expect(true, J_U, J_U); 736 expect(true, J_U, J_U);
728 expect(false, J_U, A_T); 737 expect(false, J_U, A_T);
729 } 738 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698