Skip to content

Fix crash when using arithmetic expressions in pattern matching#3593

Merged
eileencodes merged 1 commit intoruby:mainfrom
Shopify:fix-#21460
Jul 16, 2025
Merged

Fix crash when using arithmetic expressions in pattern matching#3593
eileencodes merged 1 commit intoruby:mainfrom
Shopify:fix-#21460

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
Collaborator

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

@eileencodes eileencodes merged commit feb2ad6 into ruby:main Jul 16, 2025
56 checks passed
@st0012 st0012 deleted the fix-#21460 branch July 16, 2025 17:12
@st0012
Copy link
Member Author

st0012 commented Jul 16, 2025

@eileencodes Thanks!

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.

3 participants