| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
| 8 | 8 |
| 9 import '../closure.dart'; | 9 import '../closure.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 3547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3558 /// returns [:true:] if an error can be statically determined. | 3558 /// returns [:true:] if an error can be statically determined. |
| 3559 bool checkTypeVariableBounds( | 3559 bool checkTypeVariableBounds( |
| 3560 ast.NewExpression node, ResolutionInterfaceType type) { | 3560 ast.NewExpression node, ResolutionInterfaceType type) { |
| 3561 if (!options.enableTypeAssertions) return false; | 3561 if (!options.enableTypeAssertions) return false; |
| 3562 | 3562 |
| 3563 Map<ResolutionDartType, Set<ResolutionDartType>> seenChecksMap = | 3563 Map<ResolutionDartType, Set<ResolutionDartType>> seenChecksMap = |
| 3564 new Map<ResolutionDartType, Set<ResolutionDartType>>(); | 3564 new Map<ResolutionDartType, Set<ResolutionDartType>>(); |
| 3565 bool definitelyFails = false; | 3565 bool definitelyFails = false; |
| 3566 | 3566 |
| 3567 void addTypeVariableBoundCheck( | 3567 void addTypeVariableBoundCheck( |
| 3568 GenericType instance, | 3568 ResolutionInterfaceType instance, |
| 3569 ResolutionDartType typeArgument, | 3569 ResolutionDartType typeArgument, |
| 3570 ResolutionTypeVariableType typeVariable, | 3570 ResolutionTypeVariableType typeVariable, |
| 3571 ResolutionDartType bound) { | 3571 ResolutionDartType bound) { |
| 3572 if (definitelyFails) return; | 3572 if (definitelyFails) return; |
| 3573 | 3573 |
| 3574 int subtypeRelation = types.computeSubtypeRelation(typeArgument, bound); | 3574 int subtypeRelation = types.computeSubtypeRelation(typeArgument, bound); |
| 3575 if (subtypeRelation == Types.IS_SUBTYPE) return; | 3575 if (subtypeRelation == DartTypes.IS_SUBTYPE) return; |
| 3576 | 3576 |
| 3577 String message = "Can't create an instance of malbounded type '$type': " | 3577 String message = "Can't create an instance of malbounded type '$type': " |
| 3578 "'${typeArgument}' is not a subtype of bound '${bound}' for " | 3578 "'${typeArgument}' is not a subtype of bound '${bound}' for " |
| 3579 "type variable '${typeVariable}' of type " | 3579 "type variable '${typeVariable}' of type " |
| 3580 "${type == instance | 3580 "${type == instance |
| 3581 ? "'${type.element.thisType}'" | 3581 ? "'${type.element.thisType}'" |
| 3582 : "'${instance.element.thisType}' on the supertype " | 3582 : "'${instance.element.thisType}' on the supertype " |
| 3583 "'${instance}' of '${type}'" | 3583 "'${instance}' of '${type}'" |
| 3584 }."; | 3584 }."; |
| 3585 if (subtypeRelation == Types.NOT_SUBTYPE) { | 3585 if (subtypeRelation == DartTypes.NOT_SUBTYPE) { |
| 3586 generateTypeError(node, message); | 3586 generateTypeError(node, message); |
| 3587 definitelyFails = true; | 3587 definitelyFails = true; |
| 3588 return; | 3588 return; |
| 3589 } else if (subtypeRelation == Types.MAYBE_SUBTYPE) { | 3589 } else if (subtypeRelation == DartTypes.MAYBE_SUBTYPE) { |
| 3590 Set<ResolutionDartType> seenChecks = seenChecksMap.putIfAbsent( | 3590 Set<ResolutionDartType> seenChecks = seenChecksMap.putIfAbsent( |
| 3591 typeArgument, () => new Set<ResolutionDartType>()); | 3591 typeArgument, () => new Set<ResolutionDartType>()); |
| 3592 if (!seenChecks.contains(bound)) { | 3592 if (!seenChecks.contains(bound)) { |
| 3593 seenChecks.add(bound); | 3593 seenChecks.add(bound); |
| 3594 assertIsSubtype(node, typeArgument, bound, message); | 3594 assertIsSubtype(node, typeArgument, bound, message); |
| 3595 } | 3595 } |
| 3596 } | 3596 } |
| 3597 } | 3597 } |
| 3598 | 3598 |
| 3599 types.checkTypeVariableBounds(type, addTypeVariableBoundCheck); | 3599 types.checkTypeVariableBounds(type, addTypeVariableBoundCheck); |
| 3600 if (definitelyFails) { | 3600 if (definitelyFails) { |
| 3601 return true; | 3601 return true; |
| 3602 } | 3602 } |
| 3603 for (ResolutionInterfaceType supertype in type.element.allSupertypes) { | 3603 for (ResolutionInterfaceType supertype in type.element.allSupertypes) { |
| 3604 ResolutionDartType instance = type.asInstanceOf(supertype.element); | 3604 ResolutionInterfaceType instance = type.asInstanceOf(supertype.element); |
| 3605 types.checkTypeVariableBounds(instance, addTypeVariableBoundCheck); | 3605 types.checkTypeVariableBounds(instance, addTypeVariableBoundCheck); |
| 3606 if (definitelyFails) { | 3606 if (definitelyFails) { |
| 3607 return true; | 3607 return true; |
| 3608 } | 3608 } |
| 3609 } | 3609 } |
| 3610 return false; | 3610 return false; |
| 3611 } | 3611 } |
| 3612 | 3612 |
| 3613 visitStaticSend(ast.Send node) { | 3613 visitStaticSend(ast.Send node) { |
| 3614 internalError(node, "Unexpected visitStaticSend"); | 3614 internalError(node, "Unexpected visitStaticSend"); |
| (...skipping 3197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6812 this.oldReturnLocal, | 6812 this.oldReturnLocal, |
| 6813 this.oldReturnType, | 6813 this.oldReturnType, |
| 6814 this.oldResolvedAst, | 6814 this.oldResolvedAst, |
| 6815 this.oldStack, | 6815 this.oldStack, |
| 6816 this.oldLocalsHandler, | 6816 this.oldLocalsHandler, |
| 6817 this.inTryStatement, | 6817 this.inTryStatement, |
| 6818 this.allFunctionsCalledOnce, | 6818 this.allFunctionsCalledOnce, |
| 6819 this.oldElementInferenceResults) | 6819 this.oldElementInferenceResults) |
| 6820 : super(function); | 6820 : super(function); |
| 6821 } | 6821 } |
| OLD | NEW |