Skip to content

Add test documenting variable binding persistence in failed patterns#4

Draft
Copilot wants to merge 6 commits intopattern_matchingfrom
copilot/sub-pr-3
Draft

Add test documenting variable binding persistence in failed patterns#4
Copilot wants to merge 6 commits intopattern_matchingfrom
copilot/sub-pr-3

Conversation

Copy link

Copilot AI commented Feb 10, 2026

Addresses clarification from @hasumikin that variables bound during pattern matching persist even when the pattern fails to match completely, matching CRuby semantics.

Changes

  • Added test case documenting variable binding behavior across failed pattern clauses

Example

a = 99
result = case [1, 2]
in [a, 3]      # Fails to match, but a is bound to 1
  :first
in [b, 2]      # Matches, a still has value 1 (not 99)
  [a, b]
end
p result       #=> [1, 1]

This confirms the current implementation in PM_LOCAL_VARIABLE_TARGET_NODE (lines 687-696 of src/codegen_prism.inc) is correct and matches CRuby behavior.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: hasumikin <8454208+hasumikin@users.noreply.github.com>
Copilot AI changed the title [WIP] Update implementation for pattern matching support Add test documenting variable binding persistence in failed patterns Feb 10, 2026
Copilot AI requested a review from hasumikin February 10, 2026 05:43
@hasumikin hasumikin force-pushed the pattern_matching branch 3 times, most recently from bfa030a to 2f873a0 Compare February 12, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants