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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 /// If both types are `int`, the returned type is `int`. | 111 /// If both types are `int`, the returned type is `int`. |
112 /// If either type is `double`, the returned type is `double`. | 112 /// If either type is `double`, the returned type is `double`. |
113 /// If both types refer to the same type variable (typically with `num` as | 113 /// If both types refer to the same type variable (typically with `num` as |
114 /// the upper bound), then that type variable is returned. | 114 /// the upper bound), then that type variable is returned. |
115 /// Otherwise `num` is returned. | 115 /// Otherwise `num` is returned. |
116 DartType getTypeOfOverloadedArithmetic(DartType type1, DartType type2) { | 116 DartType getTypeOfOverloadedArithmetic(DartType type1, DartType type2) { |
117 if (type1 == type2) return type1; | 117 if (type1 == type2) return type1; |
118 if (type1 == doubleType || type2 == doubleType) return doubleType; | 118 if (type1 == doubleType || type2 == doubleType) return doubleType; |
119 return numType; | 119 return numType; |
120 } | 120 } |
| 121 |
| 122 /// Returns true if [class_] has no proper subtypes that are usable as type |
| 123 /// argument. |
| 124 bool isSealedClass(Class class_) { |
| 125 // The sealed core classes have subtypes in the patched SDK, but those |
| 126 // classes cannot occur as type argument. |
| 127 if (class_ == coreTypes.intClass || |
| 128 class_ == coreTypes.doubleClass || |
| 129 class_ == coreTypes.stringClass || |
| 130 class_ == coreTypes.boolClass || |
| 131 class_ == coreTypes.nullClass) { |
| 132 return true; |
| 133 } |
| 134 return !hierarchy.hasProperSubtypes(class_); |
| 135 } |
121 } | 136 } |
122 | 137 |
123 /// The part of [TypeEnvironment] that deals with subtype tests. | 138 /// The part of [TypeEnvironment] that deals with subtype tests. |
124 /// | 139 /// |
125 /// 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. |
126 abstract class SubtypeTester { | 141 abstract class SubtypeTester { |
127 InterfaceType get objectType; | 142 InterfaceType get objectType; |
128 InterfaceType get rawFunctionType; | 143 InterfaceType get rawFunctionType; |
129 ClassHierarchy get hierarchy; | 144 ClassHierarchy get hierarchy; |
130 | 145 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 if (subtypeNameIndex == subtype.namedParameters.length) return false; | 236 if (subtypeNameIndex == subtype.namedParameters.length) return false; |
222 NamedType subtypeParameter = subtype.namedParameters[subtypeNameIndex]; | 237 NamedType subtypeParameter = subtype.namedParameters[subtypeNameIndex]; |
223 // Termination: Both types shrink in size. | 238 // Termination: Both types shrink in size. |
224 if (!isSubtypeOf(supertypeParameter.type, subtypeParameter.type)) { | 239 if (!isSubtypeOf(supertypeParameter.type, subtypeParameter.type)) { |
225 return false; | 240 return false; |
226 } | 241 } |
227 } | 242 } |
228 return true; | 243 return true; |
229 } | 244 } |
230 } | 245 } |
OLD | NEW |