Closed
Description
This works fine if you make Expr
invariant. It will not work with Covariance or Invariance. They both fail with the same error.
trait Value
sealed trait Expr[-I]
case class Lit(i: Int) extends Expr[Value]
def matchExpr[I](expr: Expr[I]): Expr[I] =
expr match {
case Lit(i) => Lit(i)
}
Error:
-- [E007] Type Mismatch Error: /tmp/scastie6519525892041936582/src/main/scala/main.scala:11:24
11 | case Lit(i) => Lit(i)
| ^^^^^^
| found: Main.Lit
| required: Main.Expr[I]