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 | 7 import |
7 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' | 8 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' |
8 show ContainerTypeMask, TypeMask; | 9 show ContainerTypeMask, TypeMask; |
9 | 10 |
10 import 'compiler_helper.dart'; | 11 import 'compiler_helper.dart'; |
11 import 'parser_helper.dart'; | 12 import 'parser_helper.dart'; |
12 | 13 |
13 | 14 |
14 String generateTest(String listAllocation) { | 15 String generateTest(String listAllocation) { |
15 return """ | 16 return """ |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 doTest('[]', nullify: false); // Test literal list. | 183 doTest('[]', nullify: false); // Test literal list. |
183 doTest('new List()', nullify: false); // Test growable list. | 184 doTest('new List()', nullify: false); // Test growable list. |
184 doTest('new List(1)', nullify: true); // Test fixed list. | 185 doTest('new List(1)', nullify: true); // Test fixed list. |
185 doTest('new List.filled(1, 0)', nullify: false); // Test List.filled. | 186 doTest('new List.filled(1, 0)', nullify: false); // Test List.filled. |
186 doTest('new List.filled(1, null)', nullify: true); // Test List.filled. | 187 doTest('new List.filled(1, null)', nullify: true); // Test List.filled. |
187 } | 188 } |
188 | 189 |
189 void doTest(String allocation, {bool nullify}) { | 190 void doTest(String allocation, {bool nullify}) { |
190 Uri uri = new Uri(scheme: 'source'); | 191 Uri uri = new Uri(scheme: 'source'); |
191 var compiler = compilerFor(generateTest(allocation), uri); | 192 var compiler = compilerFor(generateTest(allocation), uri); |
192 compiler.runCompiler(uri); | 193 asyncTest(() => compiler.runCompiler(uri).then((_) { |
193 var typesTask = compiler.typesTask; | 194 var typesTask = compiler.typesTask; |
194 var typesInferrer = typesTask.typesInferrer; | 195 var typesInferrer = typesTask.typesInferrer; |
195 | 196 |
196 checkType(String name, type) { | 197 checkType(String name, type) { |
197 var element = findElement(compiler, name); | 198 var element = findElement(compiler, name); |
198 ContainerTypeMask mask = typesInferrer.getTypeOfElement(element); | 199 ContainerTypeMask mask = typesInferrer.getTypeOfElement(element); |
199 if (nullify) type = type.nullable(); | 200 if (nullify) type = type.nullable(); |
200 Expect.equals(type, mask.elementType.simplify(compiler), name); | 201 Expect.equals(type, mask.elementType.simplify(compiler), name); |
201 } | 202 } |
202 | 203 |
203 checkType('listInField', typesTask.numType); | 204 checkType('listInField', typesTask.numType); |
204 checkType('listPassedToMethod', typesTask.numType); | 205 checkType('listPassedToMethod', typesTask.numType); |
205 checkType('listReturnedFromMethod', typesTask.numType); | 206 checkType('listReturnedFromMethod', typesTask.numType); |
206 checkType('listUsedWithCascade', typesTask.numType); | 207 checkType('listUsedWithCascade', typesTask.numType); |
207 checkType('listUsedInClosure', typesTask.numType); | 208 checkType('listUsedInClosure', typesTask.numType); |
208 checkType('listPassedToSelector', typesTask.numType); | 209 checkType('listPassedToSelector', typesTask.numType); |
209 checkType('listReturnedFromSelector', typesTask.numType); | 210 checkType('listReturnedFromSelector', typesTask.numType); |
210 checkType('listUsedWithAddAndInsert', typesTask.numType); | 211 checkType('listUsedWithAddAndInsert', typesTask.numType); |
211 checkType('listUsedWithConstraint', typesTask.numType); | 212 checkType('listUsedWithConstraint', typesTask.numType); |
212 checkType('listEscapingFromSetter', typesTask.numType); | 213 checkType('listEscapingFromSetter', typesTask.numType); |
213 checkType('listUsedInLocal', typesTask.numType); | 214 checkType('listUsedInLocal', typesTask.numType); |
214 checkType('listEscapingInSetterValue', typesTask.numType); | 215 checkType('listEscapingInSetterValue', typesTask.numType); |
215 checkType('listEscapingInIndex', typesTask.numType); | 216 checkType('listEscapingInIndex', typesTask.numType); |
216 checkType('listEscapingInIndexSet', typesTask.intType); | 217 checkType('listEscapingInIndexSet', typesTask.intType); |
217 checkType('listEscapingTwiceInIndexSet', typesTask.numType); | 218 checkType('listEscapingTwiceInIndexSet', typesTask.numType); |
218 checkType('listSetInNonFinalField', typesTask.numType); | 219 checkType('listSetInNonFinalField', typesTask.numType); |
219 checkType('listWithChangedLength', typesTask.intType.nullable()); | 220 checkType('listWithChangedLength', typesTask.intType.nullable()); |
220 | 221 |
221 checkType('listPassedToClosure', typesTask.dynamicType); | 222 checkType('listPassedToClosure', typesTask.dynamicType); |
222 checkType('listReturnedFromClosure', typesTask.dynamicType); | 223 checkType('listReturnedFromClosure', typesTask.dynamicType); |
223 checkType('listUsedWithNonOkSelector', typesTask.dynamicType); | 224 checkType('listUsedWithNonOkSelector', typesTask.dynamicType); |
224 checkType('listPassedAsOptionalParameter', typesTask.dynamicType); | 225 checkType('listPassedAsOptionalParameter', typesTask.dynamicType); |
225 checkType('listPassedAsNamedParameter', typesTask.dynamicType); | 226 checkType('listPassedAsNamedParameter', typesTask.dynamicType); |
226 | 227 |
227 if (!allocation.contains('filled')) { | 228 if (!allocation.contains('filled')) { |
228 checkType('listUnset', new TypeMask.nonNullEmpty()); | 229 checkType('listUnset', new TypeMask.nonNullEmpty()); |
229 checkType('listOnlySetWithConstraint', new TypeMask.nonNullEmpty()); | 230 checkType('listOnlySetWithConstraint', new TypeMask.nonNullEmpty()); |
230 } | 231 } |
| 232 })); |
231 } | 233 } |
OLD | NEW |