Skip to content

Commit 1b9ea89

Browse files
committed
Fix compiler crash in PatternMatcher
My understanding is that the test case in i24504 is expected to take this branch: https://github.com/scala/scala3/blob/0470ec1ff46a822ca58e204587fb67d56004623a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala#L420 where we the info is comming from https://github.com/scala/scala3/blob/0470ec1ff46a822ca58e204587fb67d56004623a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala#L118-L124 that has called `dropNamedTuple` https://github.com/scala/scala3/blob/0470ec1ff46a822ca58e204587fb67d56004623a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala#L113-L115 the problem is that under this case the type will be `NamedTuple.From` for which `isNamedTupleType` returns false. Which means that the returned type will not be a `NonEmptyTupleType`. The fix in this mr adds a `normalized.dealias` call in `isNormalizedTupleType` which brings it inline with `stripNormalizedTupleType`. But seems feasible that a better fix could be that `NamedTuple.From` should have already been removed earlier. But it not clear to me if that possible. fixes: i24504
1 parent ce94491 commit 1b9ea89

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class TypeUtils:
156156
else
157157
self
158158

159-
def isNamedTupleType(using Context): Boolean = self match
159+
def isNamedTupleType(using Context): Boolean = self.normalized.dealias match
160160
case defn.NamedTuple(_, _) => true
161161
case _ => false
162162

tests/pos/i24504.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Unpack {
2+
trait Expr[T] {
3+
type Fields = NamedTuple.From[T]
4+
}
5+
final case class Pair(a: Int, b: Int)
6+
def unapply(e: Expr[Pair]): e.Fields = ???
7+
8+
val x: Expr[Pair] = ???
9+
x match {
10+
case Unpack(_, _) => ???
11+
}
12+
}

0 commit comments

Comments
 (0)