isSubtypeOf method

  1. @override
bool isSubtypeOf(
  1. XPathType other
)
override

Whether this type is equal to or a subtype of other.

Implementation

@override
bool isSubtypeOf(XPathType other) {
  if (super.isSubtypeOf(other)) return true;
  if (other is XPathMapType) {
    return keyType.isSubtypeOf(other.keyType) &&
        valueType.isSubtypeOf(other.valueType);
  }
  // A map(K, V) is also a subtype of function(T) as R if:
  // - T is a supertype of K (or T is xs:anyAtomicType), i.e. K.isSubtypeOf(T)
  // - V is a subtype of R
  if (other is XPathFunctionType) {
    if (other.isAny) return true;
    final params = other.parameterTypes!;
    if (params.length != 1) return false;
    if (!keyType.isSubtypeOf(params[0])) return false;
    final ret = other.returnType;
    if (ret != null && !valueType.isSubtypeOf(ret)) return false;
    return true;
  }
  return false;
}