Given the heterogeneous type:
trait Request {
type Result
}
trait IntRequest extends Request {
type Result = Int
}
How can I make the Scala compiler happy to return a path dependent type based on pattern matching:
def test(in: Request): in.Result = in match {
case i: IntRequest => 1234
case _ => sys.error(s"Unsupported request $in")
}
Error:
<console>:53: error: type mismatch;
found : Int(1234)
required: in.Result
case i: IntRequest => 1234
^
source
share