Skip to content

Fix crash when using arithmetic expressions in pattern matching #3593

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Jul 1, 2025

Fixes https://bugs.ruby-lang.org/issues/21460

When arithmetic expressions like -1**2 are used in pattern matching contexts, Ruby crashes with "Unexpected node type in pattern matching expression: PM_CALL_NODE". This happens because the Prism parser creates PM_CALL_NODE for arithmetic operations, but Ruby's pattern matching compiler doesn't handle call nodes.

This fix adds validation to reject PM_CALL_NODE in pattern contexts with a proper syntax error.

@st0012 st0012 force-pushed the fix-#21460 branch 2 times, most recently from 395a305 to 5976ad6 Compare July 1, 2025 14:50
When arithmetic expressions like `-1**2` are used in pattern matching contexts,
Ruby crashes with "Unexpected node type in pattern matching expression: PM_CALL_NODE".
This happens because the Prism parser creates `PM_CALL_NODE` for arithmetic operations,
but Ruby's pattern matching compiler doesn't handle call nodes.

This fix adds validation to reject `PM_CALL_NODE` in pattern contexts with a proper
syntax error.
@Earlopain
Copy link
Contributor

Looks like this also fixes #3381 (basically the same issue)

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