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