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

MirroredElemTypes for Tuples #13859

Closed
TimWSpence opened this issue Nov 1, 2021 · 2 comments · Fixed by #14003
Closed

MirroredElemTypes for Tuples #13859

TimWSpence opened this issue Nov 1, 2021 · 2 comments · Fixed by #14003
Assignees
Milestone

Comments

@TimWSpence
Copy link
Contributor

Compiler version

3.1.0

Minimized code

import scala.deriving.*

type Kind[C, O[_]] = C {
  type MirroredType[X] = O[X]
  type MirroredMonoType = O[Any]
  type MirroredElemTypes[_] <: Tuple
}
  
type ProductGeneric[O[_]] = Kind[Mirror.Product, O]

type Test = [X] =>> (X, Boolean)

val x = summon[ProductGeneric[Test]]

Output

Compile with scalac -Xprint:typer:

[[syntax trees at end of                     typer]] // broken.scala
package <empty> {
  import scala.deriving.*
  final lazy module val broken$package: broken$package = new broken$package()
  final module class broken$package() extends Object() {
    this: broken$package.type =>
    type Kind[C >: Nothing <: Any, O[_ >: Nothing <: Any] >: Nothing <: Any] =
      C
        {
          type MirroredType[X >: Nothing <: Any] = O[X]
          type MirroredMonoType = O[Any]
          type MirroredElemTypes[_ >: Nothing <: Any] >: Nothing <: Tuple
        }
    type ProductGeneric[O[_ >: Nothing <: Any] >: Nothing <: Any] =
      Kind[deriving.Mirror.Product, O]
    type Test[X >: Nothing <: Any] = Tuple2[X, Boolean]
    val x:

        (
          deriving.Mirror.Product{
            MirroredType[X] = (X, Boolean); MirroredMonoType = (Any, Boolean);
              MirroredElemTypes[_$2] <: Tuple
          }
         &
          scala.deriving.Mirror.Product{
            MirroredMonoType = (?, Boolean); MirroredType[X] = (X, Boolean);
              MirroredLabel = ("Tuple2" : String)
          }
        ){
          MirroredElemTypes[X] = (=> T1, => T2);
            MirroredElemLabels = (("_1" : String), ("_2" : String))
        }

     =
      {
        final class $anon() extends Object() {
          type MirroredMonoType = (?, Boolean)
        }
        (new $anon():Object)
      }.$asInstanceOf[

          (
            deriving.Mirror.Product{
              MirroredType[X] = (X, Boolean); MirroredMonoType = (Any, Boolean)
                ;
              MirroredElemTypes[_$2] <: Tuple
            }
           &
            scala.deriving.Mirror.Product{
              MirroredMonoType = (?, Boolean); MirroredType[X] = (X, Boolean);
                MirroredLabel = ("Tuple2" : String)
            }
          ){
            MirroredElemTypes[X] = (=> T1, => T2);
              MirroredElemLabels = (("_1" : String), ("_2" : String))
          }

      ]
  }
}

Expectation

We should see MirroredElemTypes[X] = (X, Boolean).

If we replace type Test = [X] =>> (X, Boolean) with case class Test[X](l: X, r: Boolean) then it works as expected.

For context, this arose when investigating typelevel/shapeless-3#46.

@milessabin
Copy link
Contributor

I'm fairly sure this worked as intended while I was working on type class derivation in the compiler and seems to have regressed some time before 3.0.0.

@joroKr21
Copy link
Member

Another interesting one - try out type Swap[X, Y] = (Y, X) :trollface:

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.

5 participants