Hi, I work on decreasing the generated byte code, so I try to replace simple enum with union type. But despite TypeTest addition matches are not exhaustive. Could you help me?
enum U:
case S(s: String)
case I(i: Int)
type U = S | I
object U {
opaque type S = String
opaque type I = I
object S:
inline def apply(inline s: S): S = s
inline def unapply(inline s: S): Some[String] = Some(s)
given TypeTest[Any, S] with
def unapply(x: Any): Option[S & x.type] = x match
case s: String => Some(s.asInstanceOf[S & x.type])
case _ => None
object I:
inline def apply(inline i: I): I = i
inline def unapply(inline i: I): Some[Int] = Some(i)
given TypeTest[Any, I] with
def unapply(x: Any): Option[I & x.type] = x match
case i: I => Some(p.asInstanceOf[I & x.type])
case _ => None
x match
case _: S =>
case _: I =>
x match
| ^
|match may not be exhaustive.
|
|It would fail on pattern case: _: S, _: I