isA method

  1. @override
bool isA(
  1. HTType? other
)
override

Check wether value of this HTType can be assigned to other HTType.

Implementation

@override
bool isA(HTType? other) {
  assert(other?.isResolved ?? true);

  if (other == null) return true;

  if (other.isTop) return true;

  if (other.isBottom) return false;

  if (other is HTNominalType) {
    if (isNullable != other.isNullable) return false;
    if (typeArgs.length != other.typeArgs.length) return false;
    for (var i = 0; i < typeArgs.length; ++i) {
      final arg = typeArgs[i];
      if (arg.isNotA(other.typeArgs[i])) return false;
    }

    if (id == other.id) {
      return true;
    } else if (klass != null) {
      var curSuperType = klass!.superType;
      while (curSuperType != null) {
        final curSuperClass = (curSuperType as HTNominalType).klass!;
        if (curSuperType.isA(other)) {
          return true;
        }
        curSuperType = curSuperClass.superType;
      }
      return false;
    }
  }

  return false;
}