| 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 | 6 |
| 7 import 'compiler_helper.dart'; | 7 import 'compiler_helper.dart'; |
| 8 import 'parser_helper.dart'; | 8 import 'parser_helper.dart'; |
| 9 | 9 |
| 10 const String TEST1 = """ | 10 const String TEST1 = """ |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 test5() => (a ? new B() : new D()).foo(); | 64 test5() => (a ? new B() : new D()).foo(); |
| 65 | 65 |
| 66 // Can hit A.noSuchMethod, D.noSuchMethod and Object.noSuchMethod. | 66 // Can hit A.noSuchMethod, D.noSuchMethod and Object.noSuchMethod. |
| 67 test6() => a.bar(); | 67 test6() => a.bar(); |
| 68 | 68 |
| 69 // Can hit A.noSuchMethod. | 69 // Can hit A.noSuchMethod. |
| 70 test7() => new B().bar(); | 70 test7() => new B().bar(); |
| 71 test8() => new C().bar(); | 71 test8() => new C().bar(); |
| 72 test9() => (a ? new B() : new C()).bar(); | 72 test9() => (a ? new B() : new C()).bar(); |
| 73 | 73 |
| 74 // Can hit A.noSuchMethod, D.noSuchMethod and Object.noSuchMethod. | 74 // Can hit A.noSuchMethod and D.noSuchMethod. |
| 75 test10() => (a ? new B() : new D()).bar(); | 75 test10() => (a ? new B() : new D()).bar(); |
| 76 | 76 |
| 77 // Can hit D.noSuchMethod. | 77 // Can hit D.noSuchMethod. |
| 78 test11() => new D().bar(); | 78 test11() => new D().bar(); |
| 79 | 79 |
| 80 main() { | 80 main() { |
| 81 test1(); | 81 test1(); |
| 82 test2(); | 82 test2(); |
| 83 test3(); | 83 test3(); |
| 84 test4(); | 84 test4(); |
| 85 test5(); | 85 test5(); |
| 86 test6(); | 86 test6(); |
| 87 test7(); | 87 test7(); |
| 88 test8(); | 88 test8(); |
| 89 test9(); | 89 test9(); |
| 90 test10(); | 90 test10(); |
| 91 test11(); | 91 test11(); |
| 92 } | 92 } |
| 93 """; | 93 """; |
| 94 | 94 |
| 95 main() { | 95 main() { |
| 96 Uri uri = new Uri.fromComponents(scheme: 'source'); | 96 Uri uri = new Uri.fromComponents(scheme: 'source'); |
| 97 | 97 |
| 98 var compiler = compilerFor(TEST1, uri); | 98 var compiler = compilerFor(TEST1, uri); |
| 99 compiler.runCompiler(uri); | 99 compiler.runCompiler(uri); |
| 100 var typesInferrer = compiler.typesTask.typesInferrer; | 100 var typesInferrer = compiler.typesTask.typesInferrer; |
| 101 | 101 |
| 102 checkReturn(String name, type) { | 102 checkReturn(String name, type) { |
| 103 var element = findElement(compiler, name); | 103 var element = findElement(compiler, name); |
| 104 Expect.equals(type, typesInferrer.internal.returnTypeOf[element], name); | 104 Expect.equals( |
| 105 type, |
| 106 typesInferrer.internal.returnTypeOf[element].simplify(compiler), |
| 107 name); |
| 105 } | 108 } |
| 106 | 109 |
| 107 checkReturn('test1', typesInferrer.intType); | 110 checkReturn('test1', typesInferrer.intType); |
| 108 checkReturn('test2', typesInferrer.dynamicType); | 111 checkReturn('test2', typesInferrer.dynamicType); |
| 109 checkReturn('test3', typesInferrer.intType); | 112 checkReturn('test3', typesInferrer.intType); |
| 110 checkReturn('test4', typesInferrer.mapType); | 113 checkReturn('test4', typesInferrer.mapType); |
| 111 checkReturn('test5', typesInferrer.dynamicType); | 114 checkReturn('test5', typesInferrer.dynamicType.nonNullable()); |
| 112 checkReturn('test6', typesInferrer.dynamicType); | 115 checkReturn('test6', typesInferrer.dynamicType.nonNullable()); |
| 113 | 116 |
| 114 compiler = compilerFor(TEST2, uri); | 117 compiler = compilerFor(TEST2, uri); |
| 115 compiler.runCompiler(uri); | 118 compiler.runCompiler(uri); |
| 116 typesInferrer = compiler.typesTask.typesInferrer; | 119 typesInferrer = compiler.typesTask.typesInferrer; |
| 117 | 120 |
| 118 checkReturn('test1', typesInferrer.dynamicType); | 121 checkReturn('test1', typesInferrer.dynamicType); |
| 119 checkReturn('test2', typesInferrer.mapType); | 122 checkReturn('test2', typesInferrer.mapType); |
| 120 checkReturn('test3', typesInferrer.mapType); | 123 checkReturn('test3', typesInferrer.mapType); |
| 121 checkReturn('test4', typesInferrer.mapType); | 124 checkReturn('test4', typesInferrer.mapType); |
| 122 checkReturn('test5', typesInferrer.mapType); | 125 checkReturn('test5', typesInferrer.mapType); |
| 123 | 126 |
| 124 // TODO(ngeoffray): The reason for nullablity is because the | 127 // TODO(ngeoffray): The reason for nullablity is because the |
| 125 // inferrer thinks Object.noSuchMethod return null. Once we track | 128 // inferrer thinks Object.noSuchMethod return null. Once we track |
| 126 // aborting control flow in the analysis, we won't get the nullable | 129 // aborting control flow in the analysis, we won't get the nullable |
| 127 // anymore. | 130 // anymore. |
| 128 checkReturn('test6', typesInferrer.numType.nullable()); | 131 checkReturn('test6', typesInferrer.numType.nullable()); |
| 129 checkReturn('test7', typesInferrer.intType); | 132 checkReturn('test7', typesInferrer.intType); |
| 130 checkReturn('test8', typesInferrer.intType); | 133 checkReturn('test8', typesInferrer.intType); |
| 131 checkReturn('test9', typesInferrer.intType); | 134 checkReturn('test9', typesInferrer.intType); |
| 132 checkReturn('test10', typesInferrer.numType.nullable()); | 135 checkReturn('test10', typesInferrer.numType); |
| 133 checkReturn('test11', typesInferrer.doubleType); | 136 checkReturn('test11', typesInferrer.doubleType); |
| 134 } | 137 } |
| OLD | NEW |