| 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 "package:async_helper/async_helper.dart"; | 6 import "package:async_helper/async_helper.dart"; |
| 7 import 'compiler_helper.dart'; | 7 import 'compiler_helper.dart'; |
| 8 import 'type_mask_test_helper.dart'; | 8 import 'type_mask_test_helper.dart'; |
| 9 | 9 |
| 10 const String TEST = """ | 10 const String TEST = """ |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 returnDyn2(); | 107 returnDyn2(); |
| 108 returnInt3(); | 108 returnInt3(); |
| 109 returnDyn3(); | 109 returnDyn3(); |
| 110 returnInt4(); | 110 returnInt4(); |
| 111 returnNum1(); | 111 returnNum1(); |
| 112 returnIntOrNull(); | 112 returnIntOrNull(); |
| 113 new A().foo(); | 113 new A().foo(); |
| 114 } | 114 } |
| 115 """; | 115 """; |
| 116 | 116 |
| 117 | |
| 118 void main() { | 117 void main() { |
| 119 Uri uri = new Uri(scheme: 'source'); | 118 Uri uri = new Uri(scheme: 'source'); |
| 120 var compiler = compilerFor(TEST, uri); | 119 var compiler = compilerFor(TEST, uri); |
| 121 asyncTest(() => compiler.run(uri).then((_) { | 120 asyncTest(() => compiler.run(uri).then((_) { |
| 122 var typesInferrer = compiler.globalInference.typesInferrer; | 121 var typesInferrer = compiler.globalInference.typesInferrer; |
| 123 | 122 |
| 124 checkReturn(String name, type) { | 123 checkReturn(String name, type) { |
| 125 var element = findElement(compiler, name); | 124 var element = findElement(compiler, name); |
| 126 Expect.equals(type, | 125 Expect.equals( |
| 127 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), | 126 type, |
| 128 name); | 127 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), |
| 129 } | 128 name); |
| 129 } |
| 130 | 130 |
| 131 checkReturn('returnInt1', compiler.commonMasks.uint31Type); | 131 checkReturn('returnInt1', compiler.commonMasks.uint31Type); |
| 132 checkReturn('returnInt2', compiler.commonMasks.uint31Type); | 132 checkReturn('returnInt2', compiler.commonMasks.uint31Type); |
| 133 checkReturn('returnInt3', compiler.commonMasks.uint31Type); | 133 checkReturn('returnInt3', compiler.commonMasks.uint31Type); |
| 134 checkReturn('returnInt4', compiler.commonMasks.uint31Type); | 134 checkReturn('returnInt4', compiler.commonMasks.uint31Type); |
| 135 checkReturn('returnIntOrNull', compiler.commonMasks.uint31Type.nullable()); | 135 checkReturn( |
| 136 'returnIntOrNull', compiler.commonMasks.uint31Type.nullable()); |
| 136 | 137 |
| 137 checkReturn('returnDyn1', compiler.commonMasks.dynamicType.nonNullable()); | 138 checkReturn( |
| 138 checkReturn('returnDyn2', compiler.commonMasks.dynamicType.nonNullable()); | 139 'returnDyn1', compiler.commonMasks.dynamicType.nonNullable()); |
| 139 checkReturn('returnDyn3', compiler.commonMasks.dynamicType.nonNullable()); | 140 checkReturn( |
| 140 checkReturn('returnNum1', compiler.commonMasks.numType); | 141 'returnDyn2', compiler.commonMasks.dynamicType.nonNullable()); |
| 142 checkReturn( |
| 143 'returnDyn3', compiler.commonMasks.dynamicType.nonNullable()); |
| 144 checkReturn('returnNum1', compiler.commonMasks.numType); |
| 141 | 145 |
| 142 checkReturnInClass(String className, String methodName, type) { | 146 checkReturnInClass(String className, String methodName, type) { |
| 143 var cls = findElement(compiler, className); | 147 var cls = findElement(compiler, className); |
| 144 var element = cls.lookupLocalMember(methodName); | 148 var element = cls.lookupLocalMember(methodName); |
| 145 Expect.equals(type, | 149 Expect.equals( |
| 146 simplify(typesInferrer.getReturnTypeOfElement(element), compiler)); | 150 type, |
| 147 } | 151 simplify( |
| 148 var cls = findElement(compiler, 'A'); | 152 typesInferrer.getReturnTypeOfElement(element), compiler)); |
| 149 checkReturnInClass('A', 'foo', new TypeMask.nonNullExact(cls, | 153 } |
| 150 compiler.world)); | 154 |
| 151 })); | 155 var cls = findElement(compiler, 'A'); |
| 156 checkReturnInClass( |
| 157 'A', 'foo', new TypeMask.nonNullExact(cls, compiler.world)); |
| 158 })); |
| 152 } | 159 } |
| OLD | NEW |