| 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 27 matching lines...) Expand all Loading... |
| 38 ((a = 52) == true) && ((a = new X()) == true); | 38 ((a = 52) == true) && ((a = new X()) == true); |
| 39 return a; | 39 return a; |
| 40 } | 40 } |
| 41 | 41 |
| 42 returnDyn6() { | 42 returnDyn6() { |
| 43 var a; | 43 var a; |
| 44 a = a == 54 ? 'foo' : new X(); | 44 a = a == 54 ? 'foo' : new X(); |
| 45 return a; | 45 return a; |
| 46 } | 46 } |
| 47 | 47 |
| 48 returnDyn7b(x) => x; | |
| 49 | |
| 50 returnDyn7() { | |
| 51 var a = "foo"; | |
| 52 if (a.length == 3) a = 52; | |
| 53 if ((a is int) || (a is String && true)) returnDyn7b(a); | |
| 54 return a; | |
| 55 } | |
| 56 | |
| 57 returnDyn8(x) => x; | |
| 58 | |
| 59 test8() { | |
| 60 var a = "foo"; | |
| 61 if (a.length == 3) a = 52; | |
| 62 if ((false && a is! String) || returnDyn8(a)) return a; | |
| 63 } | |
| 64 | |
| 65 returnDyn9(x) => x; | |
| 66 | |
| 67 test9() { | |
| 68 var a = "foo"; | |
| 69 if (a.length == 3) a = 52; | |
| 70 if (!(a is bool && a is bool)) returnDyn9(a); | |
| 71 } | |
| 72 | |
| 73 main() { | 48 main() { |
| 74 returnDyn1(); | 49 returnDyn1(); |
| 75 returnDyn2(); | 50 returnDyn2(); |
| 76 returnDyn3(); | 51 returnDyn3(); |
| 77 returnDyn4(); | 52 returnDyn4(); |
| 78 returnDyn5(); | 53 returnDyn5(); |
| 79 returnDyn6(); | 54 returnDyn6(); |
| 80 returnDyn7(); | |
| 81 test8(); | |
| 82 test9(); | |
| 83 } | 55 } |
| 84 """; | 56 """; |
| 85 | 57 |
| 86 | 58 |
| 87 void main() { | 59 void main() { |
| 88 Uri uri = new Uri(scheme: 'source'); | 60 Uri uri = new Uri(scheme: 'source'); |
| 89 var compiler = compilerFor(TEST, uri); | 61 var compiler = compilerFor(TEST, uri); |
| 90 asyncTest(() => compiler.runCompiler(uri).then((_) { | 62 asyncTest(() => compiler.runCompiler(uri).then((_) { |
| 91 var typesInferrer = compiler.typesTask.typesInferrer; | 63 var typesInferrer = compiler.typesTask.typesInferrer; |
| 92 | 64 |
| 93 checkReturn(String name, type) { | 65 checkReturn(String name, type) { |
| 94 var element = findElement(compiler, name); | 66 var element = findElement(compiler, name); |
| 95 Expect.equals(type, | 67 Expect.equals(type, |
| 96 simplify(typesInferrer.getReturnTypeOfElement(element), compiler)); | 68 simplify(typesInferrer.getReturnTypeOfElement(element), compiler)); |
| 97 } | 69 } |
| 98 | 70 |
| 99 var subclassOfInterceptor = | 71 var subclassOfInterceptor = |
| 100 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); | 72 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); |
| 101 | 73 |
| 102 checkReturn('returnDyn1', subclassOfInterceptor); | 74 checkReturn('returnDyn1', subclassOfInterceptor); |
| 103 checkReturn('returnDyn2', subclassOfInterceptor); | 75 checkReturn('returnDyn2', subclassOfInterceptor); |
| 104 checkReturn('returnDyn3', subclassOfInterceptor); | 76 checkReturn('returnDyn3', subclassOfInterceptor); |
| 105 checkReturn('returnDyn4', compiler.typesTask.dynamicType.nonNullable()); | 77 checkReturn('returnDyn4', compiler.typesTask.dynamicType.nonNullable()); |
| 106 checkReturn('returnDyn5', compiler.typesTask.dynamicType.nonNullable()); | 78 checkReturn('returnDyn5', compiler.typesTask.dynamicType.nonNullable()); |
| 107 checkReturn('returnDyn6', compiler.typesTask.dynamicType.nonNullable()); | 79 checkReturn('returnDyn6', compiler.typesTask.dynamicType.nonNullable()); |
| 108 checkReturn('returnDyn7', subclassOfInterceptor); | |
| 109 checkReturn('returnDyn7b', subclassOfInterceptor); | |
| 110 checkReturn('returnDyn8', subclassOfInterceptor); | |
| 111 checkReturn('returnDyn9', subclassOfInterceptor); | |
| 112 })); | 80 })); |
| 113 } | 81 } |
| OLD | NEW |