Skip to content

Commit 97dcf78

Browse files
dwijnandmbovel
andcommitted
Widen scrutinees in TypeComparer's 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. Co-Authored-By: Matt Bovel <[email protected]>
1 parent d3a877f commit 97dcf78

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,10 @@ 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+
def widen(tp: Type) = tp match
1011+
case tp: TermRef if tp.symbol.is(InlineProxy) => tp.info
1012+
case tp => tp.widenSkolem
1013+
isSameType(widen(tp1.scrutinee), widen(tp2.scrutinee)) &&
10111014
tp1.cases.corresponds(tp2.cases)(isSubType)
10121015
case _ => false
10131016
}

tests/pos/16583.scala

Lines changed: 19 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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)