Skip to content

Higher kinded type arguments not refined by GADT pattern matching #9760

@scabug

Description

@scabug

In the following the, pattern matches should refine F to List,

object HKGADT {
  sealed trait Foo[F[_]]
  final case class Bar() extends Foo[List]

  def frob[F[_]](foo: Foo[F]): F[Int] =
    foo match {
      case Bar() => // dotc accepts the pattern, scalac doesn't.
         List(1) // both dotc and scalac error here
    }

  sealed trait Foo1[F]
  final case class Bar1() extends Foo1[Int]
  def frob1[A](foo: Foo1[A]) = foo match {
    case Bar1() => 1 // alles klar in scalac, dotc
  }
}

It doesn't because of this defensive move ... according to @retronym this,

does not treat F in the type of the scrutinee of the match as a free type param, which is needed to allow the constructor pattern of type Foo[List] to be allowed.

It turns out that this exclusion is overly conservative and the bug it was originally introduced to avoid was later fixed independently in this commit.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions