Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Issue with type inference when pattern matching against GADT that contains higher-kinded parameter. #137

Closed
Baccata opened this issue Feb 24, 2017 · 1 comment

Comments

@Baccata
Copy link

Baccata commented Feb 24, 2017

This was noticed by @sellout when porting his work on precog/matryoshka#28 to matryoshka's master branch (which uses typelevel scala). He suggested it might be tied to the SI-9760 fix.

Here's the most minimal example I could come up with.

  • Compiles with LB Scala 2.11.8
  • Does not compile with TL Scala 2.11.8
  • Does not compile with 2.12.1 (using either LB or TL)
object Test1 {

  trait ~>[A[_], B[_]] {
    def apply[I](fa: A[I]): B[I]
  }

  // HIGHER KINDED GADT

  sealed trait GADTK[A[_], I]
  final case class MemberK[A[_]](i: Int) extends GADTK[A, Int]

  def doesNotCompile[A[_]]: (GADTK[A, ?] ~> GADTK[A, ?]) =
    new (GADTK[A, ?] ~> GADTK[A, ?]) {
      def apply[I](v: GADTK[A, I]): GADTK[A, I] = v match {
        case MemberK(i) => MemberK(i)
      }
    }

  class CompilesFine[A[_]] extends (GADTK[A, ?] ~> GADTK[A, ?]) {
    def apply[I](v: GADTK[A, I]): GADTK[A, I] = v match {
      case MemberK(i) => MemberK(i)
    }
  }

  // SIMPLE GADT

  sealed trait GADT[A, I]
  case class Member[A, I](i: Int) extends GADT[A, Int]

  def compilesFine[A]: (GADT[A, ?] ~> GADT[A, ?]) =
    new (GADT[A, ?] ~> GADT[A, ?]) {
      def apply[I](v: GADT[A, I]): GADT[A, I] = v match {
        case Member(i) => Member(i)
      }
    }
}
@milessabin
Copy link
Member

This was merged in LBS 2.12.0, so the Scala JIRA is the place for this report.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants