| 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 testReturnInvokeDynamicGetter() => new A().myFactory(); |
| 355 |
| 354 get topLevelGetter => 42; | 356 get topLevelGetter => 42; |
| 355 returnDynamic() => topLevelGetter(42); | 357 returnDynamic() => topLevelGetter(42); |
| 356 returnTopLevelGetter() => topLevelGetter; | 358 returnTopLevelGetter() => topLevelGetter; |
| 357 | 359 |
| 358 class A { | 360 class A { |
| 359 factory A() = A.generative; | 361 factory A() = A.generative; |
| 360 A.generative(); | 362 A.generative(); |
| 361 operator==(other) => 42; | 363 operator==(other) => 42; |
| 362 | 364 |
| 363 get myField => 42; | 365 get myField => 42; |
| 364 set myField(a) {} | 366 set myField(a) {} |
| 365 returnInt1() => ++myField; | 367 returnInt1() => ++myField; |
| 366 returnInt2() => ++this.myField; | 368 returnInt2() => ++this.myField; |
| 367 returnInt3() => this.myField += 42; | 369 returnInt3() => this.myField += 42; |
| 368 returnInt4() => myField += 42; | 370 returnInt4() => myField += 42; |
| 369 operator[](index) => 42; | 371 operator[](index) => 42; |
| 370 operator[]= (index, value) {} | 372 operator[]= (index, value) {} |
| 371 returnInt5() => ++this[0]; | 373 returnInt5() => ++this[0]; |
| 372 returnInt6() => this[0] += 1; | 374 returnInt6() => this[0] += 1; |
| 375 |
| 376 get myFactory => () => 42; |
| 373 } | 377 } |
| 374 | 378 |
| 375 class B extends A { | 379 class B extends A { |
| 376 B() : super.generative(); | 380 B() : super.generative(); |
| 377 returnInt1() => ++new A().myField; | 381 returnInt1() => ++new A().myField; |
| 378 returnInt2() => new A().myField += 4; | 382 returnInt2() => new A().myField += 4; |
| 379 returnInt3() => ++new A()[0]; | 383 returnInt3() => ++new A()[0]; |
| 380 returnInt4() => new A()[0] += 42; | 384 returnInt4() => new A()[0] += 42; |
| 381 returnInt5() => ++super.myField; | 385 returnInt5() => ++super.myField; |
| 382 returnInt6() => super.myField += 4; | 386 returnInt6() => super.myField += 4; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 452 |
| 449 new B()..returnInt1() | 453 new B()..returnInt1() |
| 450 ..returnInt2() | 454 ..returnInt2() |
| 451 ..returnInt3() | 455 ..returnInt3() |
| 452 ..returnInt4() | 456 ..returnInt4() |
| 453 ..returnInt5() | 457 ..returnInt5() |
| 454 ..returnInt6() | 458 ..returnInt6() |
| 455 ..returnInt7() | 459 ..returnInt7() |
| 456 ..returnInt8() | 460 ..returnInt8() |
| 457 ..returnInt9(); | 461 ..returnInt9(); |
| 462 testReturnInvokeDynamicGetter(); |
| 458 } | 463 } |
| 459 """; | 464 """; |
| 460 | 465 |
| 461 void main() { | 466 void main() { |
| 462 Uri uri = new Uri(scheme: 'source'); | 467 Uri uri = new Uri(scheme: 'source'); |
| 463 var compiler = compilerFor(TEST, uri); | 468 var compiler = compilerFor(TEST, uri); |
| 464 compiler.runCompiler(uri); | 469 compiler.runCompiler(uri); |
| 465 var typesInferrer = compiler.typesTask.typesInferrer; | 470 var typesInferrer = compiler.typesTask.typesInferrer; |
| 466 | 471 |
| 467 checkReturn(String name, type) { | 472 checkReturn(String name, type) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 checkReturn('testLabeledIf', typesInferrer.intType.nullable()); | 525 checkReturn('testLabeledIf', typesInferrer.intType.nullable()); |
| 521 checkReturn('testSwitch1', typesInferrer.intType | 526 checkReturn('testSwitch1', typesInferrer.intType |
| 522 .union(typesInferrer.doubleType, compiler).nullable().simplify(compiler)); | 527 .union(typesInferrer.doubleType, compiler).nullable().simplify(compiler)); |
| 523 checkReturn('testSwitch2', typesInferrer.intType); | 528 checkReturn('testSwitch2', typesInferrer.intType); |
| 524 checkReturn('testSwitch3', interceptorType.nullable()); | 529 checkReturn('testSwitch3', interceptorType.nullable()); |
| 525 checkReturn('testSwitch4', typesInferrer.intType); | 530 checkReturn('testSwitch4', typesInferrer.intType); |
| 526 checkReturn('testContinue1', interceptorType.nullable()); | 531 checkReturn('testContinue1', interceptorType.nullable()); |
| 527 checkReturn('testBreak1', interceptorType.nullable()); | 532 checkReturn('testBreak1', interceptorType.nullable()); |
| 528 checkReturn('testContinue2', interceptorType.nullable()); | 533 checkReturn('testContinue2', interceptorType.nullable()); |
| 529 checkReturn('testBreak2', typesInferrer.intType.nullable()); | 534 checkReturn('testBreak2', typesInferrer.intType.nullable()); |
| 535 checkReturn('testReturnInvokeDynamicGetter', typesInferrer.dynamicType); |
| 530 | 536 |
| 531 checkReturnInClass(String className, String methodName, type) { | 537 checkReturnInClass(String className, String methodName, type) { |
| 532 var cls = findElement(compiler, className); | 538 var cls = findElement(compiler, className); |
| 533 var element = cls.lookupLocalMember(buildSourceString(methodName)); | 539 var element = cls.lookupLocalMember(buildSourceString(methodName)); |
| 534 Expect.equals(type, | 540 Expect.equals(type, |
| 535 typesInferrer.internal.returnTypeOf[element].simplify(compiler)); | 541 typesInferrer.internal.returnTypeOf[element].simplify(compiler)); |
| 536 } | 542 } |
| 537 | 543 |
| 538 checkReturnInClass('A', 'returnInt1', typesInferrer.intType); | 544 checkReturnInClass('A', 'returnInt1', typesInferrer.intType); |
| 539 checkReturnInClass('A', 'returnInt2', typesInferrer.intType); | 545 checkReturnInClass('A', 'returnInt2', typesInferrer.intType); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 554 checkReturnInClass('B', 'returnInt9', typesInferrer.intType); | 560 checkReturnInClass('B', 'returnInt9', typesInferrer.intType); |
| 555 | 561 |
| 556 checkFactoryConstructor(String className) { | 562 checkFactoryConstructor(String className) { |
| 557 var cls = findElement(compiler, className); | 563 var cls = findElement(compiler, className); |
| 558 var element = cls.localLookup(buildSourceString(className)); | 564 var element = cls.localLookup(buildSourceString(className)); |
| 559 Expect.equals(new TypeMask.nonNullExact(cls.rawType), | 565 Expect.equals(new TypeMask.nonNullExact(cls.rawType), |
| 560 typesInferrer.internal.returnTypeOf[element]); | 566 typesInferrer.internal.returnTypeOf[element]); |
| 561 } | 567 } |
| 562 checkFactoryConstructor('A'); | 568 checkFactoryConstructor('A'); |
| 563 } | 569 } |
| OLD | NEW |