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

Inconsistent success with compiling GADT pattern matching. #4482

Closed
TomasMikula opened this issue May 8, 2018 · 1 comment
Closed

Inconsistent success with compiling GADT pattern matching. #4482

TomasMikula opened this issue May 8, 2018 · 1 comment

Comments

@TomasMikula
Copy link
Contributor

First, I'm pleasantly surprised that this compiles with dotc (with scalac, it doesn't):

sealed abstract class ===[A, B]

case class Refl[A]() extends ===[A, A]

object === {

  def substitute[F[_], A, B](fa: F[A])(ev: A === B): F[B] = ev match {
    case Refl() => fa
  }

}

However, if I move the substitute method directly onto ===, it doesn't compile anymore:

sealed abstract class ===[A, B] {

  def substitute[F[_]](fa: F[A]): F[B] = this match {
    case Refl() => fa
  }

}

case class Refl[A]() extends ===[A, A]
-- [E007] Type Mismatch Error: leibniz.scala:4:19 ------------------------------
4 |    case Refl() => fa
  |                   ^^
  |                   found:    F[A](fa)
  |                   required: F[B]
  |                   
one error found

Making it an "extension" method doesn't help, either:

sealed abstract class ===[A, B]

case class Refl[A]() extends ===[A, A]

object === {

  implicit class Ops[A, B](ev: A === B) {
    def substitute[F[_]](fa: F[A]): F[B] = ev match {
      case Refl() => fa
    }
  }

}
-- [E007] Type Mismatch Error: leibniz.scala:9:21 ------------------------------
9 |      case Refl() => fa
  |                     ^^
  |                     found:    F[A](fa)
  |                     required: F[B]
  |                     
one error found
@smarter
Copy link
Member

smarter commented May 8, 2018

Duplicate of #4323, WIP PR at #4351

@smarter smarter closed this as completed May 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants