Skip to content

Commit

Permalink
Properly dealias tuple types when specializing (#18724)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 20, 2023
2 parents db39e36 + 22b273f commit b2cd869
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
15 changes: 7 additions & 8 deletions compiler/src/dotty/tools/dotc/transform/SpecializeTuples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ class SpecializeTuples extends MiniPhase:
end transformApply

override def transformSelect(tree: Select)(using Context): Tree = tree match
case Select(qual, nme._1) if isAppliedSpecializableTuple(qual.tpe.widen) =>
Select(qual, nme._1.specializedName(qual.tpe.widen.argInfos.slice(0, 1)))
case Select(qual, nme._2) if isAppliedSpecializableTuple(qual.tpe.widen) =>
Select(qual, nme._2.specializedName(qual.tpe.widen.argInfos.slice(1, 2)))
case Select(qual, name @ (nme._1 | nme._2)) =>
qual.tpe.widenDealias match
case AppliedType(tycon, args) if defn.isSpecializableTuple(tycon.classSymbol, args) =>
val argIdx = if name == nme._1 then 0 else 1
Select(qual, name.specializedName(args(argIdx) :: Nil))
case _ =>
tree
case _ => tree

private def isAppliedSpecializableTuple(tp: Type)(using Context) = tp match
case AppliedType(tycon, args) => defn.isSpecializableTuple(tycon.classSymbol, args)
case _ => false
end SpecializeTuples

object SpecializeTuples:
Expand Down
18 changes: 18 additions & 0 deletions tests/run/i18638.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type U[H, T] = (Unit, Unit)
object O:
opaque type U[H, T] <: (Unit, Unit) = (Unit, Unit)
def u: U[Int, Int] = ((), ())


def test1(u: (Unit, Unit)) = u._1
def test2(u: U[Int, Int]) = u._1
def test3(u: O.U[Int, Int]) = u._1
def test4() =
(((), ()): U[Int, Int]) match
case ((), ()) => println("ok")

@main def Test: Unit =
test1(((), ()))
test2(((), ()))
test3(O.u)
test4()

0 comments on commit b2cd869

Please sign in to comment.