OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 '../common.dart'; | 5 import '../common.dart'; |
6 import '../elements/elements.dart'; | 6 import '../elements/elements.dart'; |
7 import '../elements/entities.dart'; | 7 import '../elements/entities.dart'; |
8 import '../elements/resolution_types.dart' | 8 import '../elements/resolution_types.dart' |
9 show ResolutionDartType, ResolutionInterfaceType; | 9 show ResolutionDartType, ResolutionInterfaceType; |
10 import '../tree/dartstring.dart'; | 10 import '../tree/dartstring.dart'; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 275 |
276 /** | 276 /** |
277 * Returns the intersection between [type] and [annotation]. | 277 * Returns the intersection between [type] and [annotation]. |
278 * [isNullable] indicates whether the annotation implies a null | 278 * [isNullable] indicates whether the annotation implies a null |
279 * type. | 279 * type. |
280 */ | 280 */ |
281 TypeInformation narrowType( | 281 TypeInformation narrowType( |
282 TypeInformation type, ResolutionDartType annotation, | 282 TypeInformation type, ResolutionDartType annotation, |
283 {bool isNullable: true}) { | 283 {bool isNullable: true}) { |
284 if (annotation.treatAsDynamic) return type; | 284 if (annotation.treatAsDynamic) return type; |
285 if (annotation.isVoid) return nullType; | 285 if (annotation.isVoid) return type; |
286 if (annotation.element == closedWorld.commonElements.objectClass && | 286 if (annotation.element == closedWorld.commonElements.objectClass && |
287 isNullable) { | 287 isNullable) { |
288 return type; | 288 return type; |
289 } | 289 } |
290 TypeMask otherType; | 290 TypeMask otherType; |
291 if (annotation.isTypedef || annotation.isFunctionType) { | 291 if (annotation.isTypedef || annotation.isFunctionType) { |
292 otherType = functionType.type; | 292 otherType = functionType.type; |
293 } else if (annotation.isTypeVariable) { | 293 } else if (annotation.isTypeVariable) { |
294 // TODO(ngeoffray): Narrow to bound. | 294 // TODO(ngeoffray): Narrow to bound. |
295 return type; | 295 return type; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 TypeMask newType = null; | 552 TypeMask newType = null; |
553 for (TypeMask mask in list) { | 553 for (TypeMask mask in list) { |
554 newType = newType == null ? mask : newType.union(mask, closedWorld); | 554 newType = newType == null ? mask : newType.union(mask, closedWorld); |
555 // Likewise - stop early if we already reach dynamic. | 555 // Likewise - stop early if we already reach dynamic. |
556 if (newType.containsAll(closedWorld)) return dynamicType; | 556 if (newType.containsAll(closedWorld)) return dynamicType; |
557 } | 557 } |
558 | 558 |
559 return newType ?? const TypeMask.nonNullEmpty(); | 559 return newType ?? const TypeMask.nonNullEmpty(); |
560 } | 560 } |
561 } | 561 } |
OLD | NEW |