Skip to content

GADT matching with variant type parameters is not supported #2985

Closed
@Jacoby6000

Description

@Jacoby6000

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]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions