| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.type_environment; | 4 library kernel.type_environment; |
| 5 | 5 |
| 6 import 'ast.dart'; | 6 import 'ast.dart'; |
| 7 import 'class_hierarchy.dart'; | 7 import 'class_hierarchy.dart'; |
| 8 import 'core_types.dart'; | 8 import 'core_types.dart'; |
| 9 import 'type_algebra.dart'; | 9 import 'type_algebra.dart'; |
| 10 | 10 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 /// The part of [TypeEnvironment] that deals with subtype tests. | 138 /// The part of [TypeEnvironment] that deals with subtype tests. |
| 139 /// | 139 /// |
| 140 /// This lives in a separate class so it can be tested independently of the SDK. | 140 /// This lives in a separate class so it can be tested independently of the SDK. |
| 141 abstract class SubtypeTester { | 141 abstract class SubtypeTester { |
| 142 InterfaceType get objectType; | 142 InterfaceType get objectType; |
| 143 InterfaceType get rawFunctionType; | 143 InterfaceType get rawFunctionType; |
| 144 ClassHierarchy get hierarchy; | 144 ClassHierarchy get hierarchy; |
| 145 | 145 |
| 146 /// Returns true if [subtype] is a subtype of [supertype]. | 146 /// Returns true if [subtype] is a subtype of [supertype]. |
| 147 bool isSubtypeOf(DartType subtype, DartType supertype) { | 147 bool isSubtypeOf(DartType subtype, DartType supertype) { |
| 148 subtype = subtype.unalias; |
| 149 supertype = supertype.unalias; |
| 148 if (identical(subtype, supertype)) return true; | 150 if (identical(subtype, supertype)) return true; |
| 149 if (subtype is BottomType) return true; | 151 if (subtype is BottomType) return true; |
| 150 if (supertype is DynamicType || | 152 if (supertype is DynamicType || |
| 151 supertype is VoidType || | 153 supertype is VoidType || |
| 152 supertype == objectType) { | 154 supertype == objectType) { |
| 153 return true; | 155 return true; |
| 154 } | 156 } |
| 155 if (subtype is InterfaceType && supertype is InterfaceType) { | 157 if (subtype is InterfaceType && supertype is InterfaceType) { |
| 156 var upcastType = | 158 var upcastType = |
| 157 hierarchy.getTypeAsInstanceOf(subtype, supertype.classNode); | 159 hierarchy.getTypeAsInstanceOf(subtype, supertype.classNode); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 if (subtypeNameIndex == subtype.namedParameters.length) return false; | 238 if (subtypeNameIndex == subtype.namedParameters.length) return false; |
| 237 NamedType subtypeParameter = subtype.namedParameters[subtypeNameIndex]; | 239 NamedType subtypeParameter = subtype.namedParameters[subtypeNameIndex]; |
| 238 // Termination: Both types shrink in size. | 240 // Termination: Both types shrink in size. |
| 239 if (!isSubtypeOf(supertypeParameter.type, subtypeParameter.type)) { | 241 if (!isSubtypeOf(supertypeParameter.type, subtypeParameter.type)) { |
| 240 return false; | 242 return false; |
| 241 } | 243 } |
| 242 } | 244 } |
| 243 return true; | 245 return true; |
| 244 } | 246 } |
| 245 } | 247 } |
| OLD | NEW |