isSubtypeOf method
Checks if this type is a subtype of other.
Implementation
@override
bool isSubtypeOf(RuntimeType other, {Object? value}) {
if (other is FunctionRuntimeType) {
// An untyped function type matches any function and vice-versa.
if (_isUntyped || other._isUntyped) return true;
// Return type is covariant.
if (!_runtimeTypeCompatible(returnType, other.returnType)) return false;
// Required positional parameters must line up 1:1 (contravariant).
if (positionalParameterTypes.length !=
other.positionalParameterTypes.length) {
return false;
}
for (var i = 0; i < positionalParameterTypes.length; i++) {
if (!_runtimeTypeCompatible(
other.positionalParameterTypes[i], positionalParameterTypes[i])) {
return false;
}
}
// Named parameters: every named parameter the supertype declares must be
// present here with a contravariant-compatible type.
for (final entry in other.namedParameterTypes.entries) {
final mine = namedParameterTypes[entry.key];
if (mine == null) return false;
if (!_runtimeTypeCompatible(entry.value, mine)) return false;
}
return true;
}
// Every function is a `Function` and an `Object`.
return _isWildcardTypeName(other.name) || other.name == 'Function';
}