Given a heterogeneous type:
trait Request {
type Result
}
trait IntRequest extends Request {
type Result = Int
}
How can I make the Scala compiler happy about return a path dependent type based on a pattern match:
def test(in: Request): in.Result = in match {
case i: IntRequest => 1234
case _ => sys.error(s"Unsupported request $in")
}
The error:
<console>:53: error: type mismatch;
found : Int(1234)
required: in.Result
case i: IntRequest => 1234
^
Map
however, so the type parameters are lost from the compiler point of view. That's why I like to use type members here. – Aerograph