Skip to content

Commit 58a02d8

Browse files
committed
Teach TypeComparer's to widen scrutinees in compareMatch
If the skolem-widened scrutinees are the same and the cases correspond, then the match types are the same. Also, with inlining the type embeded in inlining's Typed expression will be without going through type-avoidance, so they won't be skolems. So we look to widen inline proxy term refs, in addition to skolems.
1 parent 74ab7a9 commit 58a02d8

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
10071007
case tp1: MatchType =>
10081008
def compareMatch = tp2 match {
10091009
case tp2: MatchType =>
1010-
isSameType(tp1.scrutinee, tp2.scrutinee) &&
1010+
val scr1 = tp1.scrutinee.widenSkolem
1011+
val scr2 = tp2.scrutinee.widenSkolem
1012+
val scr1b = if scr1.termSymbol.is(InlineProxy) then scr1.widenTermRefExpr else scr1
1013+
val scr2b = if scr2.termSymbol.is(InlineProxy) then scr2.widenTermRefExpr else scr2
1014+
isSameType(scr1b, scr2b) &&
10111015
tp1.cases.corresponds(tp2.cases)(isSubType)
10121016
case _ => false
10131017
}

tests/pos/16583.scala

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import scala.compiletime.constValueTuple
2+
3+
val ll0: Tuple3["one", "two", "three"] = constValueTuple[("one", "two", "three")]
4+
val ll1 = constValueTuple[("one", "two", "three")].toList
5+
val ll3: List["one" | ("two" | ("three" | Nothing))] = constValueTuple[("one", "two", "three")].toList
6+
val ll4: List["one" | ("two" | "three")] = constValueTuple[("one", "two", "three")].toList
7+
8+
inline def labels[Labels <: Tuple](using ev: Tuple.Union[Labels] <:< String): List[String] =
9+
val tmp = constValueTuple[Labels].toList
10+
ev.substituteCo(tmp)
11+
12+
def test = labels[("one", "two", "three")]
13+
14+
def toList(x: Tuple): List[Tuple.Union[x.type]] = ???
15+
def test2[Labels <: Tuple] = toList((???): Labels)
16+
17+
def i16654 =
18+
def t1: Tuple = EmptyTuple
19+
val t2 = t1.toList

tests/pos/16654.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def toCsvFlat[A <: Product](a: A)(using m: scala.deriving.Mirror.ProductOf[A]) = {
2+
def flatTuple(any: Any): Tuple = any match
3+
case p: Product => p.productIterator.map(flatTuple).foldLeft(EmptyTuple: Tuple)(_ ++ _)
4+
case a => Tuple1(a)
5+
6+
val tuple = flatTuple(Tuple.fromProductTyped(a)).toList
7+
}

0 commit comments

Comments
 (0)