In scala 3, when using an inline match, how do I make sure two type params are the same.
class Div[A,B]
transparent inline def simplify [A](a: QuantityUnit[A]) =
inline a match {
// only match if a and b are the same
case _: Div[a,b] /* a =:= b */ => "string"
case _ => 24
}
// should produce 24 because the type params are different
val a: String = simplify(new Div[Boolean,Int])
// should produce "string" because the type params are the same
val b: Int = simplify(new Div[Boolean,Boolean])
This is the key line, I would like to express what is commented out:
case _: Div[a,b] /* a =:= b */ => "string"
The best I've come up with is something like this:
case _: Div[a,b] => inline erasedValue[b] match {
case _: a => "string"
case _ => ...
}
But it forces me to break out of the main match statement.