Skip to content

Commit 0258dc3

Browse files
mboveldwijnand
andcommitted
Widen skolem in scrutinee when normalizing match aliase
Co-Authored-By: Dale Wijnand <dale.wijnand@gmail.com>
1 parent b3f2102 commit 0258dc3

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4478,7 +4478,15 @@ object Types {
44784478
case MatchAlias(alias) =>
44794479
trace(i"normalize $this", typr, show = true) {
44804480
MatchTypeTrace.recurseWith(this) {
4481-
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
4481+
alias.applyIfParameterized(args.map(_.normalized)) match
4482+
case mt @ MatchType(bound, scrutinee, cases) =>
4483+
val scrutinee1 = scrutinee.widenSkolem
4484+
if scrutinee1 ne scrutinee then
4485+
mt.derivedMatchType(bound, scrutinee.widenSkolem, cases).normalized
4486+
else
4487+
mt.tryNormalize
4488+
case mt =>
4489+
mt.tryNormalize
44824490
}
44834491
}
44844492
case _ =>

tests/pos/16583.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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)

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)