| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 while (true) { | 344 while (true) { |
| 345 b = a + 54; | 345 b = a + 54; |
| 346 if (b == 42) { | 346 if (b == 42) { |
| 347 a = 'foo'; | 347 a = 'foo'; |
| 348 break; | 348 break; |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 return b; | 351 return b; |
| 352 } | 352 } |
| 353 | 353 |
| 354 testReturnElementOfConstList1() { |
| 355 return const [42][0]; |
| 356 } |
| 357 |
| 358 testReturnElementOfConstList2() { |
| 359 return topLevelConstList[0]; |
| 360 } |
| 361 |
| 362 var topLevelConstList = const [42]; |
| 363 |
| 354 get topLevelGetter => 42; | 364 get topLevelGetter => 42; |
| 355 returnDynamic() => topLevelGetter(42); | 365 returnDynamic() => topLevelGetter(42); |
| 356 returnTopLevelGetter() => topLevelGetter; | 366 returnTopLevelGetter() => topLevelGetter; |
| 357 | 367 |
| 358 class A { | 368 class A { |
| 359 factory A() = A.generative; | 369 factory A() = A.generative; |
| 360 A.generative(); | 370 A.generative(); |
| 361 operator==(other) => 42; | 371 operator==(other) => 42; |
| 362 | 372 |
| 363 get myField => 42; | 373 get myField => 42; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 458 |
| 449 new B()..returnInt1() | 459 new B()..returnInt1() |
| 450 ..returnInt2() | 460 ..returnInt2() |
| 451 ..returnInt3() | 461 ..returnInt3() |
| 452 ..returnInt4() | 462 ..returnInt4() |
| 453 ..returnInt5() | 463 ..returnInt5() |
| 454 ..returnInt6() | 464 ..returnInt6() |
| 455 ..returnInt7() | 465 ..returnInt7() |
| 456 ..returnInt8() | 466 ..returnInt8() |
| 457 ..returnInt9(); | 467 ..returnInt9(); |
| 468 testReturnElementOfConstList1(); |
| 469 testReturnElementOfConstList2(); |
| 458 } | 470 } |
| 459 """; | 471 """; |
| 460 | 472 |
| 461 void main() { | 473 void main() { |
| 462 Uri uri = new Uri(scheme: 'source'); | 474 Uri uri = new Uri(scheme: 'source'); |
| 463 var compiler = compilerFor(TEST, uri); | 475 var compiler = compilerFor(TEST, uri); |
| 464 compiler.runCompiler(uri); | 476 compiler.runCompiler(uri); |
| 465 var typesInferrer = compiler.typesTask.typesInferrer; | 477 var typesInferrer = compiler.typesTask.typesInferrer; |
| 466 | 478 |
| 467 checkReturn(String name, type) { | 479 checkReturn(String name, type) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 checkReturn('testLabeledIf', typesInferrer.intType.nullable()); | 532 checkReturn('testLabeledIf', typesInferrer.intType.nullable()); |
| 521 checkReturn('testSwitch1', typesInferrer.intType | 533 checkReturn('testSwitch1', typesInferrer.intType |
| 522 .union(typesInferrer.doubleType, compiler).nullable().simplify(compiler)); | 534 .union(typesInferrer.doubleType, compiler).nullable().simplify(compiler)); |
| 523 checkReturn('testSwitch2', typesInferrer.intType); | 535 checkReturn('testSwitch2', typesInferrer.intType); |
| 524 checkReturn('testSwitch3', interceptorType.nullable()); | 536 checkReturn('testSwitch3', interceptorType.nullable()); |
| 525 checkReturn('testSwitch4', typesInferrer.intType); | 537 checkReturn('testSwitch4', typesInferrer.intType); |
| 526 checkReturn('testContinue1', interceptorType.nullable()); | 538 checkReturn('testContinue1', interceptorType.nullable()); |
| 527 checkReturn('testBreak1', interceptorType.nullable()); | 539 checkReturn('testBreak1', interceptorType.nullable()); |
| 528 checkReturn('testContinue2', interceptorType.nullable()); | 540 checkReturn('testContinue2', interceptorType.nullable()); |
| 529 checkReturn('testBreak2', typesInferrer.intType.nullable()); | 541 checkReturn('testBreak2', typesInferrer.intType.nullable()); |
| 542 checkReturn('testReturnElementOfConstList1', typesInferrer.intType); |
| 543 checkReturn('testReturnElementOfConstList2', typesInferrer.intType); |
| 530 | 544 |
| 531 checkReturnInClass(String className, String methodName, type) { | 545 checkReturnInClass(String className, String methodName, type) { |
| 532 var cls = findElement(compiler, className); | 546 var cls = findElement(compiler, className); |
| 533 var element = cls.lookupLocalMember(buildSourceString(methodName)); | 547 var element = cls.lookupLocalMember(buildSourceString(methodName)); |
| 534 Expect.equals(type, | 548 Expect.equals(type, |
| 535 typesInferrer.internal.returnTypeOf[element].simplify(compiler)); | 549 typesInferrer.internal.returnTypeOf[element].simplify(compiler)); |
| 536 } | 550 } |
| 537 | 551 |
| 538 checkReturnInClass('A', 'returnInt1', typesInferrer.intType); | 552 checkReturnInClass('A', 'returnInt1', typesInferrer.intType); |
| 539 checkReturnInClass('A', 'returnInt2', typesInferrer.intType); | 553 checkReturnInClass('A', 'returnInt2', typesInferrer.intType); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 554 checkReturnInClass('B', 'returnInt9', typesInferrer.intType); | 568 checkReturnInClass('B', 'returnInt9', typesInferrer.intType); |
| 555 | 569 |
| 556 checkFactoryConstructor(String className) { | 570 checkFactoryConstructor(String className) { |
| 557 var cls = findElement(compiler, className); | 571 var cls = findElement(compiler, className); |
| 558 var element = cls.localLookup(buildSourceString(className)); | 572 var element = cls.localLookup(buildSourceString(className)); |
| 559 Expect.equals(new TypeMask.nonNullExact(cls.rawType), | 573 Expect.equals(new TypeMask.nonNullExact(cls.rawType), |
| 560 typesInferrer.internal.returnTypeOf[element]); | 574 typesInferrer.internal.returnTypeOf[element]); |
| 561 } | 575 } |
| 562 checkFactoryConstructor('A'); | 576 checkFactoryConstructor('A'); |
| 563 } | 577 } |
| OLD | NEW |