Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library ddc.runtime.dart_runtime; | 5 library ddc.runtime.dart_runtime; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 import 'package:dev_compiler/config.dart'; | 9 import 'package:dev_compiler/config.dart'; |
| 10 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 // Ignore named parameters - these cannot be passed positionally. | 121 // Ignore named parameters - these cannot be passed positionally. |
| 122 } else if (parameter.isOptional) { | 122 } else if (parameter.isOptional) { |
| 123 optionalPositional++; | 123 optionalPositional++; |
| 124 } else { | 124 } else { |
| 125 normal++; | 125 normal++; |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 return new Arity._internal(normal, optionalPositional); | 128 return new Arity._internal(normal, optionalPositional); |
| 129 } | 129 } |
| 130 | 130 |
| 131 bool _isFunctionSubType(TypeMirror t1, TypeMirror t2) { | |
| 132 // Function types follow the standard non-Dart rule: | |
| 133 // - contravariant on param types | |
| 134 // - covariant on return type | |
| 135 final f1 = t1 as FunctionTypeMirror; | |
| 136 final f2 = t2 as FunctionTypeMirror; | |
| 137 | |
| 138 final params1 = f1.parameters; | |
| 139 final params2 = f2.parameters; | |
| 140 final ret1 = f1.returnType; | |
| 141 final ret2 = f2.returnType; | |
| 142 return _isFunctionSubTypeHelper(ret1, params1, ret2, params2); | |
| 143 } | |
| 144 | |
| 145 bool _isFunctionSubTypeHelper(TypeMirror ret1, List<ParameterMirror> params1, | 131 bool _isFunctionSubTypeHelper(TypeMirror ret1, List<ParameterMirror> params1, |
|
Jennifer Messerly
2015/02/27 16:54:12
on second thought, I should probably rename this _
| |
| 146 TypeMirror ret2, List<ParameterMirror> params2) { | 132 TypeMirror ret2, List<ParameterMirror> params2) { |
| 147 if (!_isSubType(ret1, ret2)) { | 133 if (!_isSubType(ret1, ret2)) { |
| 148 // Covariant return types | 134 // Covariant return types |
| 149 // Note, void (which can only appear as a return type) is effectively | 135 // Note, void (which can only appear as a return type) is effectively |
| 150 // treated as dynamic. If the base return type is void, we allow any | 136 // treated as dynamic. If the base return type is void, we allow any |
| 151 // subtype return type. | 137 // subtype return type. |
| 152 // E.g., we allow: | 138 // E.g., we allow: |
| 153 // () -> int <: () -> void | 139 // () -> int <: () -> void |
| 154 if (ret2.simpleName != const Symbol('void')) { | 140 if (ret2.simpleName != const Symbol('void')) { |
| 155 return false; | 141 return false; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 ret1 = call1.returnType; | 315 ret1 = call1.returnType; |
| 330 params1 = call1.parameters; | 316 params1 = call1.parameters; |
| 331 } | 317 } |
| 332 | 318 |
| 333 // Any type that implements a call method implicitly subtypes Function. | 319 // Any type that implements a call method implicitly subtypes Function. |
| 334 if (_reflects(c2, Function)) return true; | 320 if (_reflects(c2, Function)) return true; |
| 335 | 321 |
| 336 // Check structural function subtyping | 322 // Check structural function subtyping |
| 337 return _isFunctionSubTypeHelper(ret1, params1, c2.returnType, c2.parameters); | 323 return _isFunctionSubTypeHelper(ret1, params1, c2.returnType, c2.parameters); |
| 338 } | 324 } |
| OLD | NEW |