[Major] Cannot cast a subtype to another related subtype

Summary

Unfortunately it’s not possible to perform a failable cast of a subtype to another related subtype.

Please select what you are reporting on:

Verse

What Type of Bug are you experiencing?

Verse

Steps to Reproduce

base_class := class<castable> {}
a_class := class(base_class) {}

CastTest(t: castable_subtype(base_class))<decides>: void = {
  castable_subtype(a_class)[t]
}

Expected Result

Casting a subtype to another subtype should be permitted.

Observed Result

Casting only permits to cast a value to another target value, but it’s not possible to cast a type value to another target type value.

Platform(s)

UEFN (v37.10)

Additional Notes

To quickly compare this to another language (Swift).

class Base {}
class A: Base {}
class B: Base {}

func castTest(_ t: Base.Type) -> Bool {
  if let _ = t as? A.Type {
    true
  } else {
    false
  }
}

print(castTest(A.self)) // true
print(castTest(B.self)) // false

This operation only casts the type of Base to another subtype and not their instnatiated objects.