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

Tuple.Map and upper bounds #12645

Closed
Adam-Vandervorst opened this issue May 29, 2021 · 2 comments · Fixed by #12695
Closed

Tuple.Map and upper bounds #12645

Adam-Vandervorst opened this issue May 29, 2021 · 2 comments · Fixed by #12695

Comments

@Adam-Vandervorst
Copy link

Compiler version

3.0.0-RC3

Minimized code

case class TBox[A <: Tuple](v: A)

@main def m =
    val t: TBox[EmptyTuple] = TBox(EmptyTuple) // works
    val tt: Tuple.Map[(EmptyTuple, EmptyTuple), TBox] = (TBox(EmptyTuple), TBox(EmptyTuple))

Output

Type argument TBox does not conform to upper bound [_$4] =>> Any
    val tt: Tuple.Map[(EmptyTuple, EmptyTuple), TBox] = (TBox(EmptyTuple), TBox(EmptyTuple))

Expectation

Since the first line of the main function and the snippet below work, I expected the above to work too.

case class ABox[A](v: A)

@main def main_f = {
    val a: ABox[Int] = ABox(1)
    val ta: Tuple.Map[(Int, Int), ABox] = (ABox(1), ABox(2))
@smarter
Copy link
Member

smarter commented May 29, 2021

The second parameter of Tuple.Map is F[_], meaning that one has to pass a type lambda that can be applied to any type parameter, this isn't the case of TBox which requires its type parameter to be a subtype of Tuple, hence the error message. It looks like this is fixable by changing that second parameter type to be upper-bounded by Union[Tup] instead:

object Test {
  type Map[Tup <: Tuple, F[_ <: Tuple.Union[Tup]]] <: Tuple = Tup match {
    case EmptyTuple => EmptyTuple
    case h *: t => F[h] *: Map[t, F]
  }
  case class TBox[A <: Tuple](v: A)
  val tt: Map[(EmptyTuple, EmptyTuple), TBox] = (TBox(EmptyTuple), TBox(EmptyTuple)) // now OK
}

The same change might be applicable to other match types in Tuple too /cc @nicolasstucki

@smarter
Copy link
Member

smarter commented May 29, 2021

To clarify, the fix also works when the second parameter upper-bound is not Tuple:

  case class IBox[A <: Int](v: A)
  val tt: Map[(1, 2), IBox] = (IBox(1), IBox(2)) // now OK

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 3, 2021
changvvb pushed a commit to changvvb/dotty that referenced this issue Jun 23, 2021
@Kordyjan Kordyjan added this to the 3.0.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants