Skip to content

Commit b2b0115

Browse files
bracevacaherlihy
andauthored
Account for named tuples in space subtraction (#22658)
Fixes #22245 Co-authored-by: anna herlihy <[email protected]>
2 parents 7ad8418 + 0373617 commit b2b0115

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ object SpaceEngine {
237237
else a
238238
case (a @ Typ(tp1, _), Prod(tp2, fun, ss)) =>
239239
// rationale: every instance of `tp1` is covered by `tp2(_)`
240-
if isSubType(tp1, tp2) && covers(fun, tp1, ss.length) then
240+
if isSubType(tp1.stripNamedTuple, tp2) && covers(fun, tp1, ss.length) then
241241
minus(Prod(tp1, fun, signature(fun, tp1, ss.length).map(Typ(_, false))), b)
242242
else if canDecompose(a) then minus(Or(decompose(a)), b)
243243
else a
@@ -804,8 +804,8 @@ object SpaceEngine {
804804
else tp.symbol.showName
805805
case Typ(tp, decomposed) =>
806806
val cls = tp.classSymbol
807-
if ctx.definitions.isTupleNType(tp) then
808-
params(tp).map(_ => "_").mkString("(", ", ", ")")
807+
if ctx.definitions.isTupleNType(tp.stripNamedTuple) then
808+
params(tp.stripNamedTuple).map(_ => "_").mkString("(", ", ", ")")
809809
else if defn.ListType.isRef(cls) then
810810
if flattenList then "_*" else "_: List"
811811
else if (defn.ConsType.isRef(cls))

tests/pos/named-tuples-i22245.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import language.experimental.namedTuples
2+
3+
def find(explore: List[(seen: Set[Int], x: Int, y: Int)]): Any =
4+
explore match
5+
case Nil => ???
6+
case (seen = s, x = x, y = y) :: rest => ???

0 commit comments

Comments
 (0)