Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'package:expect/expect.dart'; | |
| 6 | |
| 7 import 'compiler_helper.dart'; | |
| 8 import 'parser_helper.dart'; | |
| 9 | |
| 10 const String TEST1 = """ | |
| 11 class A { | |
| 12 noSuchMethod(im) => 42; | |
| 13 } | |
| 14 | |
| 15 class B extends A { | |
| 16 foo(); | |
| 17 } | |
| 18 | |
| 19 class C extends B { | |
| 20 foo() => {}; | |
| 21 } | |
| 22 | |
| 23 var a; | |
| 24 test1() => new A().foo(); | |
| 25 test2() => a.foo(); | |
| 26 test3() => new B().foo(); | |
| 27 test4() => new C().foo(); | |
| 28 test5() => (a ? new A() : new B()).foo(); | |
| 29 test6() => (a ? new B() : new C()).foo(); | |
| 30 | |
| 31 main() { | |
| 32 test1(); | |
| 33 test2(); | |
| 34 test3(); | |
| 35 test4(); | |
| 36 test5(); | |
| 37 test6(); | |
| 38 } | |
| 39 """; | |
| 40 | |
| 41 const String TEST2 = """ | |
| 42 abstract class A { | |
| 43 noSuchMethod(im) => 42; | |
| 44 } | |
| 45 | |
| 46 class B extends A { | |
| 47 foo() => {}; | |
| 48 } | |
| 49 | |
| 50 class C extends B { | |
| 51 foo() => {}; | |
| 52 } | |
| 53 | |
| 54 class D implements A { | |
| 55 foo() => {}; | |
| 56 noSuchMethod(im) => 42.5; | |
| 57 } | |
| 58 | |
| 59 var a; | |
| 60 test1() => a.foo(); | |
| 61 test2() => new B().foo(); | |
| 62 test3() => new C().foo(); | |
| 63 test4() => (a ? new B() : new C()).foo(); | |
| 64 test5() => (a ? new B() : new D()).foo(); | |
| 65 | |
| 66 // Can hit A.noSuchMethod, D.noSuchMethod and Object.noSuchMethod. | |
| 67 test6() => a.bar(); | |
| 68 | |
| 69 // Can hit A.noSuchMethod. | |
| 70 test7() => new B().bar(); | |
| 71 test8() => new C().bar(); | |
| 72 test9() => (a ? new B() : new C()).bar(); | |
| 73 | |
| 74 // Can hit A.noSuchMethod, D.noSuchMethod and Object.noSuchMethod. | |
| 75 test10() => (a ? new B() : new D()).bar(); | |
| 76 | |
| 77 // Can hit D.noSuchMethod. | |
| 78 test11() => new D().bar(); | |
| 79 | |
|
karlklose
2013/04/16 13:54:47
Extra line.
ngeoffray
2013/04/17 09:11:18
Done.
| |
| 80 | |
| 81 main() { | |
| 82 test1(); | |
| 83 test2(); | |
| 84 test3(); | |
| 85 test4(); | |
| 86 test5(); | |
| 87 test6(); | |
| 88 test7(); | |
| 89 test8(); | |
| 90 test9(); | |
| 91 test10(); | |
| 92 test11(); | |
| 93 } | |
| 94 """; | |
| 95 | |
| 96 main() { | |
| 97 Uri uri = new Uri.fromComponents(scheme: 'source'); | |
| 98 | |
| 99 var compiler = compilerFor(TEST1, uri); | |
| 100 compiler.runCompiler(uri); | |
| 101 var typesInferrer = compiler.typesTask.typesInferrer; | |
| 102 | |
| 103 checkReturn(String name, type) { | |
| 104 var element = findElement(compiler, name); | |
| 105 Expect.equals(type, typesInferrer.returnTypeOf[element], name); | |
| 106 } | |
| 107 | |
| 108 checkReturn('test1', typesInferrer.intType); | |
| 109 checkReturn('test2', typesInferrer.dynamicType); | |
| 110 checkReturn('test3', typesInferrer.intType); | |
| 111 checkReturn('test4', typesInferrer.mapType); | |
| 112 checkReturn('test5', typesInferrer.dynamicType); | |
| 113 checkReturn('test6', typesInferrer.dynamicType); | |
| 114 | |
| 115 compiler = compilerFor(TEST2, uri); | |
| 116 compiler.runCompiler(uri); | |
| 117 typesInferrer = compiler.typesTask.typesInferrer; | |
| 118 | |
| 119 checkReturn('test1', typesInferrer.dynamicType); | |
| 120 checkReturn('test2', typesInferrer.mapType); | |
| 121 checkReturn('test3', typesInferrer.mapType); | |
| 122 checkReturn('test4', typesInferrer.mapType); | |
| 123 checkReturn('test5', typesInferrer.mapType); | |
| 124 | |
| 125 checkReturn('test6', typesInferrer.numType.nullable()); | |
|
karlklose
2013/04/16 13:54:47
Add a comment to remove .nullable() when we can tr
ngeoffray
2013/04/17 09:11:18
Done.
| |
| 126 checkReturn('test7', typesInferrer.intType); | |
| 127 checkReturn('test8', typesInferrer.intType); | |
| 128 checkReturn('test9', typesInferrer.intType); | |
| 129 checkReturn('test10', typesInferrer.numType.nullable()); | |
| 130 checkReturn('test11', typesInferrer.doubleType); | |
| 131 } | |
| OLD | NEW |