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 'parser_helper.dart'; | 8 import 'parser_helper.dart'; |
| 9 import 'type_mask_test_helper.dart'; |
9 | 10 |
10 const String TEST = """ | 11 const String TEST = """ |
11 | 12 |
12 class A { | 13 class A { |
13 get foo => 'string'; | 14 get foo => 'string'; |
14 set foo(value) {} | 15 set foo(value) {} |
15 operator[](index) => 'string'; | 16 operator[](index) => 'string'; |
16 operator[]=(index, value) {} | 17 operator[]=(index, value) {} |
17 | 18 |
18 returnDynamic1() => foo--; | 19 returnDynamic1() => foo--; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 Uri uri = new Uri(scheme: 'source'); | 66 Uri uri = new Uri(scheme: 'source'); |
66 var compiler = compilerFor(TEST, uri); | 67 var compiler = compilerFor(TEST, uri); |
67 asyncTest(() => compiler.runCompiler(uri).then((_) { | 68 asyncTest(() => compiler.runCompiler(uri).then((_) { |
68 var typesTask = compiler.typesTask; | 69 var typesTask = compiler.typesTask; |
69 var typesInferrer = typesTask.typesInferrer; | 70 var typesInferrer = typesTask.typesInferrer; |
70 | 71 |
71 checkReturnInClass(String className, String methodName, type) { | 72 checkReturnInClass(String className, String methodName, type) { |
72 var cls = findElement(compiler, className); | 73 var cls = findElement(compiler, className); |
73 var element = cls.lookupLocalMember(methodName); | 74 var element = cls.lookupLocalMember(methodName); |
74 Expect.equals(type, | 75 Expect.equals(type, |
75 typesInferrer.getReturnTypeOfElement(element).simplify(compiler), | 76 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), |
76 methodName); | 77 methodName); |
77 } | 78 } |
78 | 79 |
79 var subclassOfInterceptor = | 80 var subclassOfInterceptor = |
80 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); | 81 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); |
81 | 82 |
82 checkReturnInClass('A', 'returnNum1', typesTask.numType); | 83 checkReturnInClass('A', 'returnNum1', typesTask.numType); |
83 checkReturnInClass('A', 'returnNum2', typesTask.numType); | 84 checkReturnInClass('A', 'returnNum2', typesTask.numType); |
84 checkReturnInClass('A', 'returnNum3', typesTask.numType); | 85 checkReturnInClass('A', 'returnNum3', typesTask.numType); |
85 checkReturnInClass('A', 'returnNum4', typesTask.numType); | 86 checkReturnInClass('A', 'returnNum4', typesTask.numType); |
86 checkReturnInClass('A', 'returnEmpty1', const TypeMask.nonNullEmpty()); | 87 checkReturnInClass('A', 'returnEmpty1', const TypeMask.nonNullEmpty()); |
87 checkReturnInClass('A', 'returnEmpty2', const TypeMask.nonNullEmpty()); | 88 checkReturnInClass('A', 'returnEmpty2', const TypeMask.nonNullEmpty()); |
88 checkReturnInClass('A', 'returnDynamic1', subclassOfInterceptor); | 89 checkReturnInClass('A', 'returnDynamic1', subclassOfInterceptor); |
89 checkReturnInClass('A', 'returnDynamic2', subclassOfInterceptor); | 90 checkReturnInClass('A', 'returnDynamic2', subclassOfInterceptor); |
90 checkReturnInClass('A', 'returnEmpty3', const TypeMask.nonNullEmpty()); | 91 checkReturnInClass('A', 'returnEmpty3', const TypeMask.nonNullEmpty()); |
91 | 92 |
92 checkReturnInClass('B', 'returnString1', typesTask.stringType); | 93 checkReturnInClass('B', 'returnString1', typesTask.stringType); |
93 checkReturnInClass('B', 'returnString2', typesTask.stringType); | 94 checkReturnInClass('B', 'returnString2', typesTask.stringType); |
94 checkReturnInClass('B', 'returnDynamic1', const TypeMask.nonNullEmpty()); | 95 checkReturnInClass('B', 'returnDynamic1', const TypeMask.nonNullEmpty()); |
95 checkReturnInClass('B', 'returnDynamic2', const TypeMask.nonNullEmpty()); | 96 checkReturnInClass('B', 'returnDynamic2', const TypeMask.nonNullEmpty()); |
96 checkReturnInClass('B', 'returnDynamic3', const TypeMask.nonNullEmpty()); | 97 checkReturnInClass('B', 'returnDynamic3', const TypeMask.nonNullEmpty()); |
97 checkReturnInClass('B', 'returnDynamic4', const TypeMask.nonNullEmpty()); | 98 checkReturnInClass('B', 'returnDynamic4', const TypeMask.nonNullEmpty()); |
98 })); | 99 })); |
99 } | 100 } |
OLD | NEW |