def remove[S](a: S | Int, f: Int => S):S = a match {
case a: S => a
case a: Int => f(a)
}
val t: Int | String = 5
val t1 = remove[String](t, _.toString)
This compiles fine, but at runtime, the call to remove will throw a java.lang.ClassCastException (Integer cannot be cast to String)