From 1b9ea89af895e49ee68c21e5ce7ab166ebc4f8f0 Mon Sep 17 00:00:00 2001 From: Emil Ejbyfeldt Date: Mon, 24 Nov 2025 14:16:49 +0100 Subject: [PATCH 1/2] 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 --- compiler/src/dotty/tools/dotc/core/TypeUtils.scala | 2 +- tests/pos/i24504.scala | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i24504.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeUtils.scala b/compiler/src/dotty/tools/dotc/core/TypeUtils.scala index 594249065d98..ff366c120de0 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeUtils.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeUtils.scala @@ -156,7 +156,7 @@ class TypeUtils: else self - def isNamedTupleType(using Context): Boolean = self match + def isNamedTupleType(using Context): Boolean = self.normalized.dealias match case defn.NamedTuple(_, _) => true case _ => false diff --git a/tests/pos/i24504.scala b/tests/pos/i24504.scala new file mode 100644 index 000000000000..ad5b700130cf --- /dev/null +++ b/tests/pos/i24504.scala @@ -0,0 +1,12 @@ +object Unpack { + trait Expr[T] { + type Fields = NamedTuple.From[T] + } + final case class Pair(a: Int, b: Int) + def unapply(e: Expr[Pair]): e.Fields = ??? + + val x: Expr[Pair] = ??? + x match { + case Unpack(_, _) => ??? + } +} From fc71afec8ccd30155705d8918bf29c0ad57d1593 Mon Sep 17 00:00:00 2001 From: Emil Ejbyfeldt Date: Tue, 25 Nov 2025 07:50:34 +0100 Subject: [PATCH 2/2] This also makes i23552 work correctly --- tests/{neg => pos}/i23552.scala | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{neg => pos}/i23552.scala (100%) diff --git a/tests/neg/i23552.scala b/tests/pos/i23552.scala similarity index 100% rename from tests/neg/i23552.scala rename to tests/pos/i23552.scala