OLD | NEW |
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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 testReturnElementOfConstList1(); | 477 testReturnElementOfConstList1(); |
478 testReturnElementOfConstList2(); | 478 testReturnElementOfConstList2(); |
479 testReturnItselfOrInt(topLevelGetter()); | 479 testReturnItselfOrInt(topLevelGetter()); |
480 testReturnInvokeDynamicGetter(); | 480 testReturnInvokeDynamicGetter(); |
481 } | 481 } |
482 """; | 482 """; |
483 | 483 |
484 void main() { | 484 void main() { |
485 Uri uri = new Uri(scheme: 'source'); | 485 Uri uri = new Uri(scheme: 'source'); |
486 var compiler = compilerFor(TEST, uri); | 486 var compiler = compilerFor(TEST, uri); |
487 compiler.runCompiler(uri); | 487 compiler.runCompiler(uri).then((_) { |
488 var typesTask = compiler.typesTask; | 488 var typesTask = compiler.typesTask; |
489 var typesInferrer = typesTask.typesInferrer; | 489 var typesInferrer = typesTask.typesInferrer; |
490 | 490 |
491 checkReturn(String name, type) { | 491 checkReturn(String name, type) { |
492 var element = findElement(compiler, name); | 492 var element = findElement(compiler, name); |
493 Expect.equals( | 493 Expect.equals( |
494 type, | 494 type, |
495 typesInferrer.getReturnTypeOfElement(element).simplify(compiler), | 495 typesInferrer.getReturnTypeOfElement(element).simplify(compiler), |
496 name); | 496 name); |
497 } | 497 } |
498 var interceptorType = | 498 var interceptorType = |
499 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); | 499 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); |
500 | 500 |
501 checkReturn('returnNum1', typesTask.numType); | 501 checkReturn('returnNum1', typesTask.numType); |
502 checkReturn('returnNum2', typesTask.numType); | 502 checkReturn('returnNum2', typesTask.numType); |
503 checkReturn('returnInt1', typesTask.intType); | 503 checkReturn('returnInt1', typesTask.intType); |
504 checkReturn('returnInt2', typesTask.intType); | 504 checkReturn('returnInt2', typesTask.intType); |
505 checkReturn('returnDouble', typesTask.doubleType); | 505 checkReturn('returnDouble', typesTask.doubleType); |
506 checkReturn('returnGiveUp', interceptorType); | 506 checkReturn('returnGiveUp', interceptorType); |
507 checkReturn('returnInt5', typesTask.intType); | 507 checkReturn('returnInt5', typesTask.intType); |
508 checkReturn('returnInt6', typesTask.intType); | 508 checkReturn('returnInt6', typesTask.intType); |
509 checkReturn('returnIntOrNull', typesTask.intType.nullable()); | 509 checkReturn('returnIntOrNull', typesTask.intType.nullable()); |
510 checkReturn('returnInt3', typesTask.intType); | 510 checkReturn('returnInt3', typesTask.intType); |
511 checkReturn('returnDynamic', typesTask.dynamicType); | 511 checkReturn('returnDynamic', typesTask.dynamicType); |
512 checkReturn('returnInt4', typesTask.intType); | 512 checkReturn('returnInt4', typesTask.intType); |
513 checkReturn('returnInt7', typesTask.intType); | 513 checkReturn('returnInt7', typesTask.intType); |
514 checkReturn('returnInt8', typesTask.intType); | 514 checkReturn('returnInt8', typesTask.intType); |
515 checkReturn('returnDynamic1', typesTask.dynamicType); | 515 checkReturn('returnDynamic1', typesTask.dynamicType); |
516 checkReturn('returnDynamic2', typesTask.dynamicType); | 516 checkReturn('returnDynamic2', typesTask.dynamicType); |
517 TypeMask intType = new TypeMask.nonNullSubtype(compiler.intClass.rawType); | 517 TypeMask intType = new TypeMask.nonNullSubtype(compiler.intClass.rawType); |
518 checkReturn('testIsCheck1', intType); | 518 checkReturn('testIsCheck1', intType); |
519 checkReturn('testIsCheck2', intType); | 519 checkReturn('testIsCheck2', intType); |
520 checkReturn('testIsCheck3', intType.nullable()); | 520 checkReturn('testIsCheck3', intType.nullable()); |
521 checkReturn('testIsCheck4', intType); | 521 checkReturn('testIsCheck4', intType); |
522 checkReturn('testIsCheck5', intType); | 522 checkReturn('testIsCheck5', intType); |
523 checkReturn('testIsCheck6', typesTask.dynamicType); | 523 checkReturn('testIsCheck6', typesTask.dynamicType); |
524 checkReturn('testIsCheck7', intType); | 524 checkReturn('testIsCheck7', intType); |
525 checkReturn('testIsCheck8', typesTask.dynamicType); | 525 checkReturn('testIsCheck8', typesTask.dynamicType); |
526 checkReturn('testIsCheck9', intType); | 526 checkReturn('testIsCheck9', intType); |
527 checkReturn('testIsCheck10', typesTask.dynamicType); | 527 checkReturn('testIsCheck10', typesTask.dynamicType); |
528 checkReturn('testIsCheck11', intType); | 528 checkReturn('testIsCheck11', intType); |
529 checkReturn('testIsCheck12', typesTask.dynamicType); | 529 checkReturn('testIsCheck12', typesTask.dynamicType); |
530 checkReturn('testIsCheck13', intType); | 530 checkReturn('testIsCheck13', intType); |
531 checkReturn('testIsCheck14', typesTask.dynamicType); | 531 checkReturn('testIsCheck14', typesTask.dynamicType); |
532 checkReturn('testIsCheck15', intType); | 532 checkReturn('testIsCheck15', intType); |
533 checkReturn('testIsCheck16', typesTask.dynamicType); | 533 checkReturn('testIsCheck16', typesTask.dynamicType); |
534 checkReturn('testIsCheck17', intType); | 534 checkReturn('testIsCheck17', intType); |
535 checkReturn('testIsCheck18', typesTask.dynamicType); | 535 checkReturn('testIsCheck18', typesTask.dynamicType); |
536 checkReturn('testIsCheck19', typesTask.dynamicType); | 536 checkReturn('testIsCheck19', typesTask.dynamicType); |
537 checkReturn('testIsCheck20', typesTask.dynamicType.nonNullable()); | 537 checkReturn('testIsCheck20', typesTask.dynamicType.nonNullable()); |
538 checkReturn('returnAsString', | 538 checkReturn('returnAsString', |
539 new TypeMask.subtype(compiler.stringClass.computeType(compiler))); | 539 new TypeMask.subtype(compiler.stringClass.computeType(compiler))); |
540 checkReturn('returnIntAsNum', typesTask.intType); | 540 checkReturn('returnIntAsNum', typesTask.intType); |
541 checkReturn('returnAsTypedef', typesTask.functionType.nullable()); | 541 checkReturn('returnAsTypedef', typesTask.functionType.nullable()); |
542 checkReturn('returnTopLevelGetter', typesTask.intType); | 542 checkReturn('returnTopLevelGetter', typesTask.intType); |
543 checkReturn('testDeadCode', typesTask.intType); | 543 checkReturn('testDeadCode', typesTask.intType); |
544 checkReturn('testLabeledIf', typesTask.intType.nullable()); | 544 checkReturn('testLabeledIf', typesTask.intType.nullable()); |
545 checkReturn('testSwitch1', typesTask.intType | 545 checkReturn('testSwitch1', typesTask.intType |
546 .union(typesTask.doubleType, compiler).nullable().simplify(compiler)); | 546 .union(typesTask.doubleType, compiler) |
547 checkReturn('testSwitch2', typesTask.intType); | 547 .nullable().simplify(compiler)); |
548 checkReturn('testSwitch3', interceptorType.nullable()); | 548 checkReturn('testSwitch2', typesTask.intType); |
549 checkReturn('testSwitch4', typesTask.intType); | 549 checkReturn('testSwitch3', interceptorType.nullable()); |
550 checkReturn('testContinue1', interceptorType.nullable()); | 550 checkReturn('testSwitch4', typesTask.intType); |
551 checkReturn('testBreak1', interceptorType.nullable()); | 551 checkReturn('testContinue1', interceptorType.nullable()); |
552 checkReturn('testContinue2', interceptorType.nullable()); | 552 checkReturn('testBreak1', interceptorType.nullable()); |
553 checkReturn('testBreak2', typesTask.intType.nullable()); | 553 checkReturn('testContinue2', interceptorType.nullable()); |
554 checkReturn('testReturnElementOfConstList1', typesTask.intType); | 554 checkReturn('testBreak2', typesTask.intType.nullable()); |
555 checkReturn('testReturnElementOfConstList2', typesTask.intType); | 555 checkReturn('testReturnElementOfConstList1', typesTask.intType); |
556 checkReturn('testReturnItselfOrInt', typesTask.intType); | 556 checkReturn('testReturnElementOfConstList2', typesTask.intType); |
557 checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType); | 557 checkReturn('testReturnItselfOrInt', typesTask.intType); |
| 558 checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType); |
558 | 559 |
559 checkReturnInClass(String className, String methodName, type) { | 560 checkReturnInClass(String className, String methodName, type) { |
560 var cls = findElement(compiler, className); | 561 var cls = findElement(compiler, className); |
561 var element = cls.lookupLocalMember(buildSourceString(methodName)); | 562 var element = cls.lookupLocalMember(buildSourceString(methodName)); |
562 Expect.equals(type, | 563 Expect.equals(type, |
563 typesInferrer.getReturnTypeOfElement(element).simplify(compiler)); | 564 typesInferrer.getReturnTypeOfElement(element).simplify(compiler)); |
564 } | 565 } |
565 | 566 |
566 checkReturnInClass('A', 'returnInt1', typesTask.intType); | 567 checkReturnInClass('A', 'returnInt1', typesTask.intType); |
567 checkReturnInClass('A', 'returnInt2', typesTask.intType); | 568 checkReturnInClass('A', 'returnInt2', typesTask.intType); |
568 checkReturnInClass('A', 'returnInt3', typesTask.intType); | 569 checkReturnInClass('A', 'returnInt3', typesTask.intType); |
569 checkReturnInClass('A', 'returnInt4', typesTask.intType); | 570 checkReturnInClass('A', 'returnInt4', typesTask.intType); |
570 checkReturnInClass('A', 'returnInt5', typesTask.intType); | 571 checkReturnInClass('A', 'returnInt5', typesTask.intType); |
571 checkReturnInClass('A', 'returnInt6', typesTask.intType); | 572 checkReturnInClass('A', 'returnInt6', typesTask.intType); |
572 checkReturnInClass('A', '==', interceptorType); | 573 checkReturnInClass('A', '==', interceptorType); |
573 | 574 |
574 checkReturnInClass('B', 'returnInt1', typesTask.intType); | 575 checkReturnInClass('B', 'returnInt1', typesTask.intType); |
575 checkReturnInClass('B', 'returnInt2', typesTask.intType); | 576 checkReturnInClass('B', 'returnInt2', typesTask.intType); |
576 checkReturnInClass('B', 'returnInt3', typesTask.intType); | 577 checkReturnInClass('B', 'returnInt3', typesTask.intType); |
577 checkReturnInClass('B', 'returnInt4', typesTask.intType); | 578 checkReturnInClass('B', 'returnInt4', typesTask.intType); |
578 checkReturnInClass('B', 'returnInt5', typesTask.intType); | 579 checkReturnInClass('B', 'returnInt5', typesTask.intType); |
579 checkReturnInClass('B', 'returnInt6', typesTask.intType); | 580 checkReturnInClass('B', 'returnInt6', typesTask.intType); |
580 checkReturnInClass('B', 'returnInt7', typesTask.intType); | 581 checkReturnInClass('B', 'returnInt7', typesTask.intType); |
581 checkReturnInClass('B', 'returnInt8', typesTask.intType); | 582 checkReturnInClass('B', 'returnInt8', typesTask.intType); |
582 checkReturnInClass('B', 'returnInt9', typesTask.intType); | 583 checkReturnInClass('B', 'returnInt9', typesTask.intType); |
583 | 584 |
584 checkFactoryConstructor(String className, String factoryName) { | 585 checkFactoryConstructor(String className, String factoryName) { |
585 var cls = findElement(compiler, className); | 586 var cls = findElement(compiler, className); |
586 var element = cls.localLookup(buildSourceString(factoryName)); | 587 var element = cls.localLookup(buildSourceString(factoryName)); |
587 Expect.equals(new TypeMask.nonNullExact(cls.rawType), | 588 Expect.equals(new TypeMask.nonNullExact(cls.rawType), |
588 typesInferrer.getReturnTypeOfElement(element)); | 589 typesInferrer.getReturnTypeOfElement(element)); |
589 } | 590 } |
590 checkFactoryConstructor('A', ''); | 591 checkFactoryConstructor('A', ''); |
| 592 }); |
591 } | 593 } |
OLD | NEW |