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 |
48 main() { | 57 main() { |
49 returnDyn1(); | 58 returnDyn1(); |
50 returnDyn2(); | 59 returnDyn2(); |
51 returnDyn3(); | 60 returnDyn3(); |
52 returnDyn4(); | 61 returnDyn4(); |
53 returnDyn5(); | 62 returnDyn5(); |
54 returnDyn6(); | 63 returnDyn6(); |
| 64 returnDyn7(); |
55 } | 65 } |
56 """; | 66 """; |
57 | 67 |
58 | 68 |
59 void main() { | 69 void main() { |
60 Uri uri = new Uri(scheme: 'source'); | 70 Uri uri = new Uri(scheme: 'source'); |
61 var compiler = compilerFor(TEST, uri); | 71 var compiler = compilerFor(TEST, uri); |
62 asyncTest(() => compiler.runCompiler(uri).then((_) { | 72 asyncTest(() => compiler.runCompiler(uri).then((_) { |
63 var typesInferrer = compiler.typesTask.typesInferrer; | 73 var typesInferrer = compiler.typesTask.typesInferrer; |
64 | 74 |
65 checkReturn(String name, type) { | 75 checkReturn(String name, type) { |
66 var element = findElement(compiler, name); | 76 var element = findElement(compiler, name); |
67 Expect.equals(type, | 77 Expect.equals(type, |
68 simplify(typesInferrer.getReturnTypeOfElement(element), compiler)); | 78 simplify(typesInferrer.getReturnTypeOfElement(element), compiler)); |
69 } | 79 } |
70 | 80 |
71 var subclassOfInterceptor = | 81 var subclassOfInterceptor = |
72 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); | 82 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); |
73 | 83 |
74 checkReturn('returnDyn1', subclassOfInterceptor); | 84 checkReturn('returnDyn1', subclassOfInterceptor); |
75 checkReturn('returnDyn2', subclassOfInterceptor); | 85 checkReturn('returnDyn2', subclassOfInterceptor); |
76 checkReturn('returnDyn3', subclassOfInterceptor); | 86 checkReturn('returnDyn3', subclassOfInterceptor); |
77 checkReturn('returnDyn4', compiler.typesTask.dynamicType.nonNullable()); | 87 checkReturn('returnDyn4', compiler.typesTask.dynamicType.nonNullable()); |
78 checkReturn('returnDyn5', compiler.typesTask.dynamicType.nonNullable()); | 88 checkReturn('returnDyn5', compiler.typesTask.dynamicType.nonNullable()); |
79 checkReturn('returnDyn6', compiler.typesTask.dynamicType.nonNullable()); | 89 checkReturn('returnDyn6', compiler.typesTask.dynamicType.nonNullable()); |
| 90 checkReturn('returnDyn7', subclassOfInterceptor); |
| 91 checkReturn('returnDyn7b', subclassOfInterceptor); |
80 })); | 92 })); |
81 } | 93 } |
OLD | NEW |