Skip to content

Incorrect mismatch in GADT match body #23925

@eejbyfeldt

Description

@eejbyfeldt

Compiler version

3.7.2 (works in scala 2)

Minimized code

object test {
  sealed trait A[T] 
  case class O[T](e: A[T]) extends A[Option[T]]

  def opt[U](v: Option[U], a: A[U]) = ???

  def f[T](a: A[T], t: T) = {
    a match {
      case O(i) => opt(t, i)
    }
  }
}

Output

-- [E007] Type Mismatch Error: match_opt.scala:10:23 ---------------------------
10 |      case O(i) => opt(t, i)
   |                       ^
   |      Found:    (t : T)
   |      Required: Option[T$1]
   |
   |      where:    T is a type in method f which is an alias of Option[T$1]
   |
   | longer explanation available when compiling with `-explain`
1 error found

Expectation

Should compile without errors.

Extra

Switching the order of the arguments to opt makes the error goes away.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions