From ece0a5feb59bc75778db5b29543231331dfdb9ff Mon Sep 17 00:00:00 2001 From: Emil Ejbyfeldt Date: Fri, 13 Jun 2025 16:05:05 +0200 Subject: [PATCH 1/2] Fix issue 23158 The fix is made based on us doing stripNamedTuple in other parts close by. Seems like made should in a single place, but I lack the bigger understanding to figure our where that would be. --- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 2 +- tests/pos/i23158.scala | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i23158.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 8ede7ba831f5..170c28d1c5de 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -581,7 +581,7 @@ object SpaceEngine { var resTp0 = mt.resultType if mt.isResultDependent then resTp0 = ctx.typeAssigner.safeSubstParam(resTp0, mt.paramRefs.head, scrutineeTp) - val resTp = wildApprox(resTp0.finalResultType) + val resTp = wildApprox(resTp0.finalResultType).stripNamedTuple val sig = if (resTp.isRef(defn.BooleanClass)) diff --git a/tests/pos/i23158.scala b/tests/pos/i23158.scala new file mode 100644 index 000000000000..228721329701 --- /dev/null +++ b/tests/pos/i23158.scala @@ -0,0 +1,11 @@ +//> using options -Werror + +object Unpack { + final case class Pair(a: Int, b: Int) + def unapply(e: Pair): NamedTuple.NamedTuple[("a", "b"), (Int, Int)] = ??? + + val x: Pair = ??? + x match { + case Unpack(_, _) => ??? + } +} From fb93fe7a9432e2994df8b274d3c28a2254090783 Mon Sep 17 00:00:00 2001 From: Emil Ejbyfeldt Date: Wed, 26 Nov 2025 16:36:21 +0100 Subject: [PATCH 2/2] Also fix inside Some --- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 2 +- tests/pos/{i23158.scala => i23158a.scala} | 0 tests/pos/i23158b.scala | 11 +++++++++++ tests/pos/i23158c.scala | 11 +++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) rename tests/pos/{i23158.scala => i23158a.scala} (100%) create mode 100644 tests/pos/i23158b.scala create mode 100644 tests/pos/i23158c.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 170c28d1c5de..387c0f1d5d42 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -602,7 +602,7 @@ object SpaceEngine { if (arity > 0) productSelectorTypes(resTp, unappSym.srcPos) else { - val getTp = extractorMemberType(resTp, nme.get, unappSym.srcPos) + val getTp = extractorMemberType(resTp, nme.get, unappSym.srcPos).stripNamedTuple if (argLen == 1) getTp :: Nil else productSelectorTypes(getTp, unappSym.srcPos) } diff --git a/tests/pos/i23158.scala b/tests/pos/i23158a.scala similarity index 100% rename from tests/pos/i23158.scala rename to tests/pos/i23158a.scala diff --git a/tests/pos/i23158b.scala b/tests/pos/i23158b.scala new file mode 100644 index 000000000000..e186592be92c --- /dev/null +++ b/tests/pos/i23158b.scala @@ -0,0 +1,11 @@ +//> using options -Werror + +object Unpack { + final case class Pair(a: Int, b: Int) + def unapply(e: Pair): (a: Int, b: Int) = ??? + + val x: Pair = ??? + x match { + case Unpack(_, _) => ??? + } +} diff --git a/tests/pos/i23158c.scala b/tests/pos/i23158c.scala new file mode 100644 index 000000000000..abe6ea90d7d2 --- /dev/null +++ b/tests/pos/i23158c.scala @@ -0,0 +1,11 @@ +//> using options -Werror + +object Unpack { + final case class Pair(a: Int, b: Int) + def unapply(e: Pair): Some[(a: Int, b: Int)] = ??? + + val x: Pair = ??? + x match { + case Unpack(_, _) => ??? + } +}