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 'package:compiler/src/types/types.dart' | 7 import 'package:compiler/src/types/types.dart' show ContainerTypeMask, TypeMask; |
8 show ContainerTypeMask, TypeMask; | |
9 | 8 |
10 import 'compiler_helper.dart'; | 9 import 'compiler_helper.dart'; |
11 import 'type_mask_test_helper.dart'; | 10 import 'type_mask_test_helper.dart'; |
12 | 11 |
13 String generateTest(String listAllocation) { | 12 String generateTest(String listAllocation) { |
14 return """ | 13 return """ |
15 int anInt = 42; | 14 int anInt = 42; |
16 double aDouble = 42.5; | 15 double aDouble = 42.5; |
17 | 16 |
18 class A { | 17 class A { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 doTest('new List(1)', nullify: true); // Test fixed list. | 191 doTest('new List(1)', nullify: true); // Test fixed list. |
193 doTest('new List.filled(1, 0)', nullify: false); // Test List.filled. | 192 doTest('new List.filled(1, 0)', nullify: false); // Test List.filled. |
194 doTest('new List.filled(1, null)', nullify: true); // Test List.filled. | 193 doTest('new List.filled(1, null)', nullify: true); // Test List.filled. |
195 } | 194 } |
196 | 195 |
197 void doTest(String allocation, {bool nullify}) { | 196 void doTest(String allocation, {bool nullify}) { |
198 Uri uri = new Uri(scheme: 'source'); | 197 Uri uri = new Uri(scheme: 'source'); |
199 var compiler = compilerFor(generateTest(allocation), uri, | 198 var compiler = compilerFor(generateTest(allocation), uri, |
200 expectedErrors: 0, expectedWarnings: 1); | 199 expectedErrors: 0, expectedWarnings: 1); |
201 asyncTest(() => compiler.run(uri).then((_) { | 200 asyncTest(() => compiler.run(uri).then((_) { |
202 var commonMasks = compiler.commonMasks; | 201 var commonMasks = compiler.commonMasks; |
203 var typesInferrer = compiler.globalInference.typesInferrer; | 202 var typesInferrer = compiler.globalInference.typesInferrer; |
204 | 203 |
205 checkType(String name, type) { | 204 checkType(String name, type) { |
206 var element = findElement(compiler, name); | 205 var element = findElement(compiler, name); |
207 ContainerTypeMask mask = typesInferrer.getTypeOfElement(element); | 206 ContainerTypeMask mask = typesInferrer.getTypeOfElement(element); |
208 if (nullify) type = type.nullable(); | 207 if (nullify) type = type.nullable(); |
209 Expect.equals(type, simplify(mask.elementType, compiler), name); | 208 Expect.equals(type, simplify(mask.elementType, compiler), name); |
210 } | 209 } |
211 | 210 |
212 checkType('listInField', commonMasks.numType); | 211 checkType('listInField', commonMasks.numType); |
213 checkType('listPassedToMethod', commonMasks.numType); | 212 checkType('listPassedToMethod', commonMasks.numType); |
214 checkType('listReturnedFromMethod', commonMasks.numType); | 213 checkType('listReturnedFromMethod', commonMasks.numType); |
215 checkType('listUsedWithCascade', commonMasks.numType); | 214 checkType('listUsedWithCascade', commonMasks.numType); |
216 checkType('listUsedInClosure', commonMasks.numType); | 215 checkType('listUsedInClosure', commonMasks.numType); |
217 checkType('listPassedToSelector', commonMasks.numType); | 216 checkType('listPassedToSelector', commonMasks.numType); |
218 checkType('listReturnedFromSelector', commonMasks.numType); | 217 checkType('listReturnedFromSelector', commonMasks.numType); |
219 checkType('listUsedWithAddAndInsert', commonMasks.numType); | 218 checkType('listUsedWithAddAndInsert', commonMasks.numType); |
220 checkType('listUsedWithConstraint', commonMasks.positiveIntType); | 219 checkType('listUsedWithConstraint', commonMasks.positiveIntType); |
221 checkType('listEscapingFromSetter', commonMasks.numType); | 220 checkType('listEscapingFromSetter', commonMasks.numType); |
222 checkType('listUsedInLocal', commonMasks.numType); | 221 checkType('listUsedInLocal', commonMasks.numType); |
223 checkType('listEscapingInSetterValue', commonMasks.numType); | 222 checkType('listEscapingInSetterValue', commonMasks.numType); |
224 checkType('listEscapingInIndex', commonMasks.numType); | 223 checkType('listEscapingInIndex', commonMasks.numType); |
225 checkType('listEscapingInIndexSet', commonMasks.uint31Type); | 224 checkType('listEscapingInIndexSet', commonMasks.uint31Type); |
226 checkType('listEscapingTwiceInIndexSet', commonMasks.numType); | 225 checkType('listEscapingTwiceInIndexSet', commonMasks.numType); |
227 checkType('listSetInNonFinalField', commonMasks.numType); | 226 checkType('listSetInNonFinalField', commonMasks.numType); |
228 checkType('listWithChangedLength', commonMasks.uint31Type.nullable()); | 227 checkType('listWithChangedLength', commonMasks.uint31Type.nullable()); |
229 | 228 |
230 checkType('listPassedToClosure', commonMasks.dynamicType); | 229 checkType('listPassedToClosure', commonMasks.dynamicType); |
231 checkType('listReturnedFromClosure', commonMasks.dynamicType); | 230 checkType('listReturnedFromClosure', commonMasks.dynamicType); |
232 checkType('listUsedWithNonOkSelector', commonMasks.dynamicType); | 231 checkType('listUsedWithNonOkSelector', commonMasks.dynamicType); |
233 checkType('listPassedAsOptionalParameter', commonMasks.numType); | 232 checkType('listPassedAsOptionalParameter', commonMasks.numType); |
234 checkType('listPassedAsNamedParameter', commonMasks.numType); | 233 checkType('listPassedAsNamedParameter', commonMasks.numType); |
235 checkType('listStoredInList', commonMasks.uint31Type); | 234 checkType('listStoredInList', commonMasks.uint31Type); |
236 checkType('listStoredInListButEscapes', commonMasks.dynamicType); | 235 checkType('listStoredInListButEscapes', commonMasks.dynamicType); |
237 | 236 |
238 if (!allocation.contains('filled')) { | 237 if (!allocation.contains('filled')) { |
239 checkType('listUnset', new TypeMask.nonNullEmpty()); | 238 checkType('listUnset', new TypeMask.nonNullEmpty()); |
240 checkType('listOnlySetWithConstraint', new TypeMask.nonNullEmpty()); | 239 checkType('listOnlySetWithConstraint', new TypeMask.nonNullEmpty()); |
241 } | 240 } |
242 })); | 241 })); |
243 } | 242 } |
OLD | NEW |