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

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

Issue 14997006: Introduce a UnionTypeMask, currently limited to 4 types. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 import 'package:expect/expect.dart'; 5 import 'package:expect/expect.dart';
6 import 6 import
7 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' 7 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'
8 show TypeMask; 8 show TypeMask;
9 9
10 import 'compiler_helper.dart'; 10 import 'compiler_helper.dart';
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 """; 436 """;
437 437
438 void main() { 438 void main() {
439 Uri uri = new Uri.fromComponents(scheme: 'source'); 439 Uri uri = new Uri.fromComponents(scheme: 'source');
440 var compiler = compilerFor(TEST, uri); 440 var compiler = compilerFor(TEST, uri);
441 compiler.runCompiler(uri); 441 compiler.runCompiler(uri);
442 var typesInferrer = compiler.typesTask.typesInferrer; 442 var typesInferrer = compiler.typesTask.typesInferrer;
443 443
444 checkReturn(String name, type) { 444 checkReturn(String name, type) {
445 var element = findElement(compiler, name); 445 var element = findElement(compiler, name);
446 Expect.equals(type, typesInferrer.internal.returnTypeOf[element], name); 446 Expect.equals(
447 type,
448 typesInferrer.internal.returnTypeOf[element].simplify(compiler),
449 name);
447 } 450 }
448 var interceptorType = 451 var interceptorType =
449 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); 452 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
450 453
451 checkReturn('returnNum1', typesInferrer.numType); 454 checkReturn('returnNum1', typesInferrer.numType);
452 checkReturn('returnNum2', typesInferrer.numType); 455 checkReturn('returnNum2', typesInferrer.numType);
453 checkReturn('returnInt1', typesInferrer.intType); 456 checkReturn('returnInt1', typesInferrer.intType);
454 checkReturn('returnInt2', typesInferrer.intType); 457 checkReturn('returnInt2', typesInferrer.intType);
455 checkReturn('returnDouble', typesInferrer.doubleType); 458 checkReturn('returnDouble', typesInferrer.doubleType);
456 checkReturn('returnGiveUp', interceptorType); 459 checkReturn('returnGiveUp', interceptorType);
(...skipping 27 matching lines...) Expand all
484 checkReturn('testIsCheck17', intType); 487 checkReturn('testIsCheck17', intType);
485 checkReturn('testIsCheck18', typesInferrer.dynamicType); 488 checkReturn('testIsCheck18', typesInferrer.dynamicType);
486 checkReturn('testIsCheck19', typesInferrer.dynamicType); 489 checkReturn('testIsCheck19', typesInferrer.dynamicType);
487 checkReturn('returnAsString', 490 checkReturn('returnAsString',
488 new TypeMask.subtype(compiler.stringClass.computeType(compiler))); 491 new TypeMask.subtype(compiler.stringClass.computeType(compiler)));
489 checkReturn('returnIntAsNum', typesInferrer.intType); 492 checkReturn('returnIntAsNum', typesInferrer.intType);
490 checkReturn('returnAsTypedef', typesInferrer.functionType.nullable()); 493 checkReturn('returnAsTypedef', typesInferrer.functionType.nullable());
491 checkReturn('returnTopLevelGetter', typesInferrer.intType); 494 checkReturn('returnTopLevelGetter', typesInferrer.intType);
492 checkReturn('testDeadCode', typesInferrer.intType); 495 checkReturn('testDeadCode', typesInferrer.intType);
493 checkReturn('testLabeledIf', typesInferrer.intType.nullable()); 496 checkReturn('testLabeledIf', typesInferrer.intType.nullable());
494 checkReturn('testSwitch1', 497 checkReturn('testSwitch1', typesInferrer.intType
495 typesInferrer.intType.union(typesInferrer.doubleType, compiler).nullable()); 498 .union(typesInferrer.doubleType, compiler).nullable().simplify(compiler));
496 checkReturn('testSwitch2', typesInferrer.intType); 499 checkReturn('testSwitch2', typesInferrer.intType);
497 checkReturn('testSwitch3', interceptorType.nullable()); 500 checkReturn('testSwitch3', interceptorType.nullable());
498 checkReturn('testContinue1', interceptorType.nullable()); 501 checkReturn('testContinue1', interceptorType.nullable());
499 checkReturn('testBreak1', interceptorType.nullable()); 502 checkReturn('testBreak1', interceptorType.nullable());
500 checkReturn('testContinue2', interceptorType.nullable()); 503 checkReturn('testContinue2', interceptorType.nullable());
501 checkReturn('testBreak2', typesInferrer.intType.nullable()); 504 checkReturn('testBreak2', typesInferrer.intType.nullable());
502 505
503 checkReturnInClass(String className, String methodName, type) { 506 checkReturnInClass(String className, String methodName, type) {
504 var cls = findElement(compiler, className); 507 var cls = findElement(compiler, className);
505 var element = cls.lookupLocalMember(buildSourceString(methodName)); 508 var element = cls.lookupLocalMember(buildSourceString(methodName));
506 Expect.equals(type, typesInferrer.internal.returnTypeOf[element]); 509 Expect.equals(type,
510 typesInferrer.internal.returnTypeOf[element].simplify(compiler));
507 } 511 }
508 512
509 checkReturnInClass('A', 'returnInt1', typesInferrer.intType); 513 checkReturnInClass('A', 'returnInt1', typesInferrer.intType);
510 checkReturnInClass('A', 'returnInt2', typesInferrer.intType); 514 checkReturnInClass('A', 'returnInt2', typesInferrer.intType);
511 checkReturnInClass('A', 'returnInt3', typesInferrer.intType); 515 checkReturnInClass('A', 'returnInt3', typesInferrer.intType);
512 checkReturnInClass('A', 'returnInt4', typesInferrer.intType); 516 checkReturnInClass('A', 'returnInt4', typesInferrer.intType);
513 checkReturnInClass('A', 'returnInt5', typesInferrer.intType); 517 checkReturnInClass('A', 'returnInt5', typesInferrer.intType);
514 checkReturnInClass('A', 'returnInt6', typesInferrer.intType); 518 checkReturnInClass('A', 'returnInt6', typesInferrer.intType);
515 checkReturnInClass('A', '==', interceptorType); 519 checkReturnInClass('A', '==', interceptorType);
516 520
517 checkReturnInClass('B', 'returnInt1', typesInferrer.intType); 521 checkReturnInClass('B', 'returnInt1', typesInferrer.intType);
518 checkReturnInClass('B', 'returnInt2', typesInferrer.intType); 522 checkReturnInClass('B', 'returnInt2', typesInferrer.intType);
519 checkReturnInClass('B', 'returnInt3', typesInferrer.intType); 523 checkReturnInClass('B', 'returnInt3', typesInferrer.intType);
520 checkReturnInClass('B', 'returnInt4', typesInferrer.intType); 524 checkReturnInClass('B', 'returnInt4', typesInferrer.intType);
521 checkReturnInClass('B', 'returnInt5', typesInferrer.intType); 525 checkReturnInClass('B', 'returnInt5', typesInferrer.intType);
522 checkReturnInClass('B', 'returnInt6', typesInferrer.intType); 526 checkReturnInClass('B', 'returnInt6', typesInferrer.intType);
523 checkReturnInClass('B', 'returnInt7', typesInferrer.intType); 527 checkReturnInClass('B', 'returnInt7', typesInferrer.intType);
524 checkReturnInClass('B', 'returnInt8', typesInferrer.intType); 528 checkReturnInClass('B', 'returnInt8', typesInferrer.intType);
525 checkReturnInClass('B', 'returnInt9', typesInferrer.intType); 529 checkReturnInClass('B', 'returnInt9', typesInferrer.intType);
526 530
527 checkFactoryConstructor(String className) { 531 checkFactoryConstructor(String className) {
528 var cls = findElement(compiler, className); 532 var cls = findElement(compiler, className);
529 var element = cls.localLookup(buildSourceString(className)); 533 var element = cls.localLookup(buildSourceString(className));
530 Expect.equals(new TypeMask.nonNullExact(cls.rawType), 534 Expect.equals(new TypeMask.nonNullExact(cls.rawType),
531 typesInferrer.internal.returnTypeOf[element]); 535 typesInferrer.internal.returnTypeOf[element]);
532 } 536 }
533 checkFactoryConstructor('A'); 537 checkFactoryConstructor('A');
534 } 538 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698