Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
scabug opened this issue Feb 24, 2017 · 6 comments

Comments

@scabug
Copy link

scabug 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 #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)
      }
    }
}
@scabug
Copy link
Author

scabug commented Feb 24, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10208?orig=1
Reporter: Olivier Mélois (Baccata)
Affected Versions: 2.12.0
See #9760

@scabug
Copy link
Author

scabug commented Feb 24, 2017

@milessabin said:
If this is a consequence of the fix for #9760 then it will most likely be a regression in 2.11.9 as well.

@scabug
Copy link
Author

scabug commented Feb 24, 2017

Greg Pfeil (sellout) said:
Yeah, just verified that reverting the #9760 fix allows this to compile. Now to understand #9760

@scabug
Copy link
Author

scabug commented Feb 24, 2017

Greg Pfeil (sellout) said:
Ok, so I think I’ve narrowed it down. While checking MemberK[Any] <:< GADTK[?A, ?I], it fails on Any <:< ?A. Note that both the type parameter to MemberK and ?A are of kind * -> *, while Any isn’t.

@scabug
Copy link
Author

scabug commented Feb 26, 2017

Olivier Mélois (Baccata) said:
Any seems to come from the resolution of A to ?A, specifically this line : https://github.com/scala/scala/blob/98a7d4ce0234dc1c4b080ecaeed9ced09d39578a/src/reflect/scala/reflect/internal/tpe/TypeConstraints.scala#L254

@scabug
Copy link
Author

scabug commented Feb 26, 2017

Greg Pfeil (sellout) said:
I submitted a patch the other night – I guess it would be good to link it here. scala/scala#5744

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

No branches or pull requests

3 participants