Skip to content

Commit

Permalink
Teach TypeComparer's to widen scrutinees in compareMatch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dwijnand committed Jun 23, 2023
1 parent 74ab7a9 commit 58a02d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
case tp1: MatchType =>
def compareMatch = tp2 match {
case tp2: MatchType =>
isSameType(tp1.scrutinee, tp2.scrutinee) &&
val scr1 = tp1.scrutinee.widenSkolem
val scr2 = tp2.scrutinee.widenSkolem
val scr1b = if scr1.termSymbol.is(InlineProxy) then scr1.widenTermRefExpr else scr1
val scr2b = if scr2.termSymbol.is(InlineProxy) then scr2.widenTermRefExpr else scr2
isSameType(scr1b, scr2b) &&
tp1.cases.corresponds(tp2.cases)(isSubType)
case _ => false
}
Expand Down
19 changes: 19 additions & 0 deletions tests/pos/16583.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import scala.compiletime.constValueTuple

val ll0: Tuple3["one", "two", "three"] = constValueTuple[("one", "two", "three")]
val ll1 = constValueTuple[("one", "two", "three")].toList
val ll3: List["one" | ("two" | ("three" | Nothing))] = constValueTuple[("one", "two", "three")].toList
val ll4: List["one" | ("two" | "three")] = constValueTuple[("one", "two", "three")].toList

inline def labels[Labels <: Tuple](using ev: Tuple.Union[Labels] <:< String): List[String] =
val tmp = constValueTuple[Labels].toList
ev.substituteCo(tmp)

def test = labels[("one", "two", "three")]

def toList(x: Tuple): List[Tuple.Union[x.type]] = ???
def test2[Labels <: Tuple] = toList((???): Labels)

def i16654 =
def t1: Tuple = EmptyTuple
val t2 = t1.toList
7 changes: 7 additions & 0 deletions tests/pos/16654.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def toCsvFlat[A <: Product](a: A)(using m: scala.deriving.Mirror.ProductOf[A]) = {
def flatTuple(any: Any): Tuple = any match
case p: Product => p.productIterator.map(flatTuple).foldLeft(EmptyTuple: Tuple)(_ ++ _)
case a => Tuple1(a)

val tuple = flatTuple(Tuple.fromProductTyped(a)).toList
}

0 comments on commit 58a02d8

Please sign in to comment.