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 | 8 |
9 const String TEST = """ | 9 const String TEST = """ |
10 returnInt1() { | 10 returnInt1() { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 void main() { | 117 void main() { |
118 Uri uri = new Uri(scheme: 'source'); | 118 Uri uri = new Uri(scheme: 'source'); |
119 var compiler = compilerFor(TEST, uri); | 119 var compiler = compilerFor(TEST, uri); |
120 asyncTest(() => compiler.runCompiler(uri).then((_) { | 120 asyncTest(() => compiler.runCompiler(uri).then((_) { |
121 var typesInferrer = compiler.typesTask.typesInferrer; | 121 var typesInferrer = compiler.typesTask.typesInferrer; |
122 | 122 |
123 checkReturn(String name, type) { | 123 checkReturn(String name, type) { |
124 var element = findElement(compiler, name); | 124 var element = findElement(compiler, name); |
125 Expect.equals(type, | 125 Expect.equals(type, |
126 typesInferrer.getReturnTypeOfElement(element).simplify(compiler)); | 126 typesInferrer.getReturnTypeOfElement(element).simplify(compiler), |
| 127 name); |
127 } | 128 } |
128 | 129 |
129 checkReturn('returnInt1', compiler.typesTask.intType); | 130 checkReturn('returnInt1', compiler.typesTask.uint31Type); |
130 checkReturn('returnInt2', compiler.typesTask.intType); | 131 checkReturn('returnInt2', compiler.typesTask.uint31Type); |
131 checkReturn('returnInt3', compiler.typesTask.intType); | 132 checkReturn('returnInt3', compiler.typesTask.uint31Type); |
132 checkReturn('returnInt4', compiler.typesTask.intType); | 133 checkReturn('returnInt4', compiler.typesTask.uint31Type); |
133 checkReturn('returnIntOrNull', compiler.typesTask.intType.nullable()); | 134 checkReturn('returnIntOrNull', compiler.typesTask.uint31Type.nullable()); |
134 | 135 |
135 checkReturn('returnDyn1', compiler.typesTask.dynamicType.nonNullable()); | 136 checkReturn('returnDyn1', compiler.typesTask.dynamicType.nonNullable()); |
136 checkReturn('returnDyn2', compiler.typesTask.dynamicType.nonNullable()); | 137 checkReturn('returnDyn2', compiler.typesTask.dynamicType.nonNullable()); |
137 checkReturn('returnDyn3', compiler.typesTask.dynamicType.nonNullable()); | 138 checkReturn('returnDyn3', compiler.typesTask.dynamicType.nonNullable()); |
138 checkReturn('returnNum1', compiler.typesTask.numType); | 139 checkReturn('returnNum1', compiler.typesTask.numType); |
139 | 140 |
140 checkReturnInClass(String className, String methodName, type) { | 141 checkReturnInClass(String className, String methodName, type) { |
141 var cls = findElement(compiler, className); | 142 var cls = findElement(compiler, className); |
142 var element = cls.lookupLocalMember(methodName); | 143 var element = cls.lookupLocalMember(methodName); |
143 Expect.equals(type, | 144 Expect.equals(type, |
144 typesInferrer.getReturnTypeOfElement(element).simplify(compiler)); | 145 typesInferrer.getReturnTypeOfElement(element).simplify(compiler)); |
145 } | 146 } |
146 var cls = findElement(compiler, 'A'); | 147 var cls = findElement(compiler, 'A'); |
147 checkReturnInClass('A', 'foo', new TypeMask.nonNullExact(cls)); | 148 checkReturnInClass('A', 'foo', new TypeMask.nonNullExact(cls)); |
148 })); | 149 })); |
149 } | 150 } |
OLD | NEW |