| 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 'package:compiler/src/types/types.dart' | 7 import 'package:compiler/src/types/types.dart' show TypeMask; |
| 8 show TypeMask; | |
| 9 | 8 |
| 10 import 'compiler_helper.dart'; | 9 import 'compiler_helper.dart'; |
| 11 import 'type_mask_test_helper.dart'; | 10 import 'type_mask_test_helper.dart'; |
| 12 | 11 |
| 13 const String TEST = """ | 12 const String TEST = """ |
| 14 returnInt1() { | 13 returnInt1() { |
| 15 var a = 42; | 14 var a = 42; |
| 16 try { | 15 try { |
| 17 a = 54; | 16 a = 54; |
| 18 } catch (e){ | 17 } catch (e){ |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 returnInt4(); | 156 returnInt4(); |
| 158 returnDyn4(); | 157 returnDyn4(); |
| 159 returnInt5(); | 158 returnInt5(); |
| 160 returnDyn5(); | 159 returnDyn5(); |
| 161 returnInt6(); | 160 returnInt6(); |
| 162 returnDyn6(); | 161 returnDyn6(); |
| 163 returnInt7(); | 162 returnInt7(); |
| 164 } | 163 } |
| 165 """; | 164 """; |
| 166 | 165 |
| 167 | |
| 168 void main() { | 166 void main() { |
| 169 Uri uri = new Uri(scheme: 'source'); | 167 Uri uri = new Uri(scheme: 'source'); |
| 170 var compiler = compilerFor(TEST, uri); | 168 var compiler = compilerFor(TEST, uri); |
| 171 asyncTest(() => compiler.run(uri).then((_) { | 169 asyncTest(() => compiler.run(uri).then((_) { |
| 172 var commonMasks = compiler.commonMasks; | 170 var commonMasks = compiler.commonMasks; |
| 173 var typesInferrer = compiler.globalInference.typesInferrer; | 171 var typesInferrer = compiler.globalInference.typesInferrer; |
| 174 | 172 |
| 175 checkReturn(String name, type) { | 173 checkReturn(String name, type) { |
| 176 var element = findElement(compiler, name); | 174 var element = findElement(compiler, name); |
| 177 Expect.equals(type, | 175 Expect.equals( |
| 178 simplify(typesInferrer.getReturnTypeOfElement(element), compiler)); | 176 type, |
| 179 } | 177 simplify( |
| 178 typesInferrer.getReturnTypeOfElement(element), compiler)); |
| 179 } |
| 180 | 180 |
| 181 checkReturn('returnInt1', commonMasks.uint31Type); | 181 checkReturn('returnInt1', commonMasks.uint31Type); |
| 182 checkReturn('returnInt2', commonMasks.uint31Type); | 182 checkReturn('returnInt2', commonMasks.uint31Type); |
| 183 checkReturn('returnInt3', commonMasks.uint31Type); | 183 checkReturn('returnInt3', commonMasks.uint31Type); |
| 184 checkReturn('returnInt4', commonMasks.uint31Type); | 184 checkReturn('returnInt4', commonMasks.uint31Type); |
| 185 checkReturn('returnInt5', commonMasks.uint31Type); | 185 checkReturn('returnInt5', commonMasks.uint31Type); |
| 186 checkReturn('returnInt6', new TypeMask.nonNullSubtype( | 186 checkReturn( |
| 187 compiler.coreClasses.intClass, compiler.world)); | 187 'returnInt6', |
| 188 new TypeMask.nonNullSubtype( |
| 189 compiler.coreClasses.intClass, compiler.world)); |
| 188 | 190 |
| 189 var subclassOfInterceptor = | 191 var subclassOfInterceptor = |
| 190 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); | 192 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); |
| 191 | 193 |
| 192 checkReturn('returnDyn1', subclassOfInterceptor); | 194 checkReturn('returnDyn1', subclassOfInterceptor); |
| 193 checkReturn('returnDyn2', subclassOfInterceptor); | 195 checkReturn('returnDyn2', subclassOfInterceptor); |
| 194 checkReturn('returnDyn3', subclassOfInterceptor); | 196 checkReturn('returnDyn3', subclassOfInterceptor); |
| 195 checkReturn('returnDyn4', subclassOfInterceptor); | 197 checkReturn('returnDyn4', subclassOfInterceptor); |
| 196 checkReturn('returnDyn5', subclassOfInterceptor); | 198 checkReturn('returnDyn5', subclassOfInterceptor); |
| 197 checkReturn('returnDyn6', commonMasks.dynamicType); | 199 checkReturn('returnDyn6', commonMasks.dynamicType); |
| 198 })); | 200 })); |
| 199 } | 201 } |
| OLD | NEW |