Skip to content

fix(parser): preserve filtered partitions in do-the-same clauses - #6854

Merged
matthewevans merged 3 commits into
mainfrom
maintainer/rescue-5774-do-same-type
Aug 2, 2026
Merged

fix(parser): preserve filtered partitions in do-the-same clauses#6854
matthewevans merged 3 commits into
mainfrom
maintainer/rescue-5774-do-same-type

Conversation

@matthewevans

@matthewevans matthewevans commented Aug 2, 2026

Copy link
Copy Markdown
Member

Rescues closed contributor PR #5774 for the then do the same for <type> cards parser pattern.

Preserves nested tracked-set filters, handles the exact Glimpse of Tomorrow continuation, and includes parser plus runtime coverage.

Summary by CodeRabbit

  • New Features

    • Added support for “do the same for ” instructions when resolving card and permanent effects.
    • Repeated effects now correctly apply to specified card types while preserving targets, zones, controllers, and related context.
    • Supports chained continuations such as “then do the same for…”.
  • Bug Fixes

    • Corrected repeated effects involving Auras and other enchantment types.
  • Tests

    • Added coverage for typed substitutions, nested selections, and multi-step effect resolution.

@matthewevans matthewevans added the bug Bug fix label Aug 2, 2026
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The parser supports type-only “do the same for <type>” continuations. It clones supported effects, replaces typed target filters, preserves tracked-set wrappers, and validates parsing and resolution with regression tests.

Changes

Typed continuation replication

Layer / File(s) Summary
Parse typed continuations
crates/engine/src/parser/oracle_effect/sequence.rs
The parser recognizes pure type substitutions, rejects predicates and type lists, and supports a following then clause.
Replicate typed effects
crates/engine/src/parser/oracle_effect/mod.rs
The parser clones supported antecedent effects and replaces direct or nested typed filters while preserving wrappers.
Validate replicated effects
crates/engine/src/parser/oracle_effect/tests.rs, crates/engine/tests/integration/issue_4779_do_same_for_type.rs, crates/engine/tests/integration/main.rs
Tests cover logical targets, zone changes, tracked-set provenance, later clauses, and battlefield resolution.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant OracleText
  participant SequenceParser
  participant EffectReplicator
  participant EffectResolver
  OracleText->>SequenceParser: parse "do the same for <type>"
  SequenceParser->>EffectReplicator: provide continuation and antecedent effect
  EffectReplicator->>EffectReplicator: replace typed target filters
  EffectReplicator->>EffectResolver: emit retyped effect
Loading

Possibly related PRs

Suggested labels: test

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the parser fix that preserves filtered partitions in “do the same for” clauses.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch maintainer/rescue-5774-do-same-type

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Parse changes introduced by this PR · 2 card(s), 3 signature(s) (baseline: main 36ac6d2a1ccb)

🟢 Added (2 signatures)

  • 1 card · ➕ ability/ChangeZoneAll · added: ChangeZoneAll (from=graveyard, target=in graveyard you control Aura, to=battlefield)
    • Affected (first 3): Estrid, the Masked
  • 1 card · ➕ ability/ChangeZoneAll · added: ChangeZoneAll (target=tracked set #0 matching Aura, to=battlefield)
    • Affected (first 3): Glimpse of Tomorrow

🔴 Removed (1 signature)

  • 1 card · ➖ ability/PutAtLibraryPosition · removed: PutAtLibraryPosition (count=Fixed { value: 1 }, position=Bottom, target=tracked set #0)
    • Affected (first 3): Glimpse of Tomorrow

2 card(s) had Oracle-text changes (errata/reprint) — excluded as non-parser.

@matthewevans
matthewevans force-pushed the maintainer/rescue-5774-do-same-type branch 4 times, most recently from e87c5c7 to 6ca6606 Compare August 2, 2026 09:21
"..., then do the same for <type> cards" replicates the immediately-preceding
mass zone-change for a sibling card type. Estrid, the Masked's ult — "Return
all non-Aura enchantment cards from your graveyard to the battlefield, then do
the same for Aura cards." — dropped the Aura return entirely (#4779): the
comma-"then do the same" tail was glued into the first clause, and the
"do the same for <type>" verb was never recognized.

Parser-only, no new engine variant:
- split_comma_clause_boundary: treat ", then do the same for <type>" as a Then
  boundary. The "do the same" verb is not in the imperative-verb table, so —
  mirroring the villainous-choice guard directly above — the continuation was
  glued into the prior clause and dropped.
- new try_parse_do_the_same_for_type recognizer + chunk-loop dispatch that clones
  the antecedent sibling effect and swaps its type filter. This is the same
  antecedent-clone mechanic try_parse_scoped_does_the_same uses for the
  player-scoped fan-out, so it emits an ordinary sibling Effect (no disposition,
  resolver, or scope added).

Estrid now emits both returns: non-Aura enchantments, then Auras — zones and
controller preserved (CR 608.2c: the antecedent action is replicated modulo the
stated type substitution). Building-block level: covers the "do the same for
<type>" clause class, not Estrid alone.

Closes #4779.
…tion

Addresses review on #5774: the general path must not touch continuations it
cannot model. Three narrowings keep the blast radius to exactly the handled
class (Estrid); every richer sibling stays exactly as before and strict-fails
until its full grammar lands (CR #1: a flagged gap beats a silent misparse).

- Recognizer (try_parse_do_the_same_for_type): drop the broader
  "repeat this process for" family; accept ONLY a pure card-type substitution —
  reject any filter carrying a FilterProp predicate (Gruesome Menageries
@matthewevans
matthewevans force-pushed the maintainer/rescue-5774-do-same-type branch from 6ca6606 to 4495e9d Compare August 2, 2026 09:22
@matthewevans
matthewevans force-pushed the maintainer/rescue-5774-do-same-type branch from 4495e9d to 34bc8e2 Compare August 2, 2026 09:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/engine/tests/integration/issue_4779_do_same_for_type.rs`:
- Around line 36-41: Update the fixture setup in issue_4779_do_same_for_type to
move both cards through the authoritative ProposedEvent::ZoneChange pipeline
instead of zones::move_to_zone, ensuring replacement effects can modify their
entry into the graveyard.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 739f6bca-243d-4602-8505-cc8aee304c09

📥 Commits

Reviewing files that changed from the base of the PR and between fa740ff and 34bc8e2.

📒 Files selected for processing (5)
  • crates/engine/src/parser/oracle_effect/mod.rs
  • crates/engine/src/parser/oracle_effect/sequence.rs
  • crates/engine/src/parser/oracle_effect/tests.rs
  • crates/engine/tests/integration/issue_4779_do_same_for_type.rs
  • crates/engine/tests/integration/main.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • crates/engine/tests/integration/main.rs
  • crates/engine/src/parser/oracle_effect/mod.rs
  • crates/engine/src/parser/oracle_effect/tests.rs
  • crates/engine/src/parser/oracle_effect/sequence.rs

Comment on lines +36 to +41
engine::game::zones::move_to_zone(
runner.state_mut(),
object_id,
Zone::Graveyard,
&mut setup_events,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use the replacement-aware zone-change pipeline for fixture setup.

zones::move_to_zone bypasses ProposedEvent::ZoneChange. This bypasses replacement effects that can modify entry to the graveyard. The test can then validate a state that normal game actions cannot produce. Set up both cards through the authoritative zone-change pipeline. CR 608.2c permits replacement effects to modify instructions. (media.wizards.com)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/engine/tests/integration/issue_4779_do_same_for_type.rs` around lines
36 - 41, Update the fixture setup in issue_4779_do_same_for_type to move both
cards through the authoritative ProposedEvent::ZoneChange pipeline instead of
zones::move_to_zone, ensuring replacement effects can modify their entry into
the graveyard.

Source: Path instructions

@matthewevans
matthewevans added this pull request to the merge queue Aug 2, 2026
Merged via the queue into main with commit 331d105 Aug 2, 2026
14 checks passed
@matthewevans
matthewevans deleted the maintainer/rescue-5774-do-same-type branch August 2, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants