Skip to content

Allow implicit matches to bind type variables #5405

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

Closed
odersky opened this issue Nov 8, 2018 · 0 comments
Closed

Allow implicit matches to bind type variables #5405

odersky opened this issue Nov 8, 2018 · 0 comments
Assignees

Comments

@odersky
Copy link
Contributor

odersky commented Nov 8, 2018

This test case currently fails:

object Mapper {

  class MapTo[A, B](val f: A => B)

  inline def mapOne[X](x: X) = implicit match {
    case m: MapTo[X, y] => m.f(x)
  }

  inline def mapTuple[Xs <: Tuple](xs: Xs) <: Tuple = xs match {
    case xs: (x1 *: xs1) =>
      implicit match {
        case m: MapTo[`x1`, y] => m.f(xs.head.asInstanceOf[x1]) *: mapTuple(xs.tail : xs1)
      }
    case () =>
      ()
  }
}
object Test extends App {
  import Mapper._

  val xs = (1, "hello")

  locally {
    implicit val i1: MapTo[Int, Double] = new MapTo[Int, Double](_.toDouble)
    implicit val i2: MapTo[String, Boolean] = new MapTo[String, Boolean](_.length > 3)

    val r1 = mapOne[X = Int](1)

    val r2 = mapTuple(xs)
  }

}

The problem is that in the type pattern MapTo[X, y] of the implicit match case

   case m: MapTo[X, y] => m.f(x)

the y is bound to a GADT bound TypeRef. But the implicit search only knows how to constrain TypeParamRefs.

Hopefully, we get closer to a solution by identifying GADT bound and constrained variables.

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