Skip to content

Commit 14f3e03

Browse files
nicolasstuckiWojciechMazur
authored andcommitted
Properly dealias tuple types when specializing
Fixes #18638 [Cherry-picked 2701a2d]
1 parent 9cd5fc2 commit 14f3e03

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

compiler/src/dotty/tools/dotc/transform/SpecializeTuples.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class SpecializeTuples extends MiniPhase:
3737
end transformApply
3838

3939
override def transformSelect(tree: Select)(using Context): Tree = tree match
40-
case Select(qual, nme._1) if isAppliedSpecializableTuple(qual.tpe.widen) =>
41-
Select(qual, nme._1.specializedName(qual.tpe.widen.argInfos.slice(0, 1)))
42-
case Select(qual, nme._2) if isAppliedSpecializableTuple(qual.tpe.widen) =>
43-
Select(qual, nme._2.specializedName(qual.tpe.widen.argInfos.slice(1, 2)))
40+
case Select(qual, nme._1) if isAppliedSpecializableTuple(qual.tpe.widenDealias) =>
41+
Select(qual, nme._1.specializedName(qual.tpe.widenDealias.argInfos.slice(0, 1)))
42+
case Select(qual, nme._2) if isAppliedSpecializableTuple(qual.tpe.widenDealias) =>
43+
Select(qual, nme._2.specializedName(qual.tpe.widenDealias.argInfos.slice(1, 2)))
4444
case _ => tree
4545

4646
private def isAppliedSpecializableTuple(tp: Type)(using Context) = tp match

tests/run/i18638.scala

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type U[H, T] = (Unit, Unit)
2+
object O:
3+
opaque type U[H, T] <: (Unit, Unit) = (Unit, Unit)
4+
def u: U[Int, Int] = ((), ())
5+
6+
7+
def test1(u: (Unit, Unit)) = u._1
8+
def test2(u: U[Int, Int]) = u._1
9+
def test3(u: O.U[Int, Int]) = u._1
10+
def test4() =
11+
(((), ()): U[Int, Int]) match
12+
case ((), ()) => println("ok")
13+
14+
@main def Test: Unit =
15+
test1(((), ()))
16+
test2(((), ()))
17+
test3(O.u)
18+
test4()

0 commit comments

Comments
 (0)