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) {
  if (other == null) return true;

  if (other.isTop) return true;

  if (other.isBottom) return false;

  if (other is! HTNominalType) return false;

  if (isNullable != other.isNullable) return false;
  if (typeArgs.length != other.typeArgs.length) return false;
  for (final arg in typeArgs) {
    if (arg.isNotA(other)) return false;
  }

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