Skip to content

Account for named tuples in space subtraction #22658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ object SpaceEngine {
else a
case (a @ Typ(tp1, _), Prod(tp2, fun, ss)) =>
// rationale: every instance of `tp1` is covered by `tp2(_)`
if isSubType(tp1, tp2) && covers(fun, tp1, ss.length) then
if isSubType(tp1.stripNamedTuple, tp2) && covers(fun, tp1, ss.length) then
minus(Prod(tp1, fun, signature(fun, tp1, ss.length).map(Typ(_, false))), b)
else if canDecompose(a) then minus(Or(decompose(a)), b)
else a
Expand Down Expand Up @@ -804,8 +804,8 @@ object SpaceEngine {
else tp.symbol.showName
case Typ(tp, decomposed) =>
val cls = tp.classSymbol
if ctx.definitions.isTupleNType(tp) then
params(tp).map(_ => "_").mkString("(", ", ", ")")
if ctx.definitions.isTupleNType(tp.stripNamedTuple) then
params(tp.stripNamedTuple).map(_ => "_").mkString("(", ", ", ")")
else if defn.ListType.isRef(cls) then
if flattenList then "_*" else "_: List"
else if (defn.ConsType.isRef(cls))
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/named-tuples-i22245.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import language.experimental.namedTuples

def find(explore: List[(seen: Set[Int], x: Int, y: Int)]): Any =
explore match
case Nil => ???
case (seen = s, x = x, y = y) :: rest => ???
Loading