You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prism accepts double wildcard with no required fields in pattern match #2915
This results in a FindPatternNode with an empty list requireds.
MRI's parser rejects this syntax (I've tried this with Ruby 3.3.3 and a 3.4.0-dev of today):
ruby -e '[1,2,3,4] => *a, *b; p a; p b'
-e:1: syntax error, unexpected *
[1,2,3,4] => *a, *b; p a; p b
ruby: compile error (SyntaxError)
The behaviour is ambiguous: if we enable the prism parser in MRI, it turns out that the whole array is put into the right splat:
ruby --parser=prism -e '[1,2,3,4] => *a, *b; p a; p b'
ruby: warning: The compiler based on the Prism parser is currently experimental and compatibility with the compiler based on parse.y is not yet complete. Please report any issues you find on the `ruby/prism` issue tracker.
[]
[1, 2, 3, 4]
But the result a = [1, 2, 3, 4]; b = [] would have been just as valid. Other combinations like a = [1]; b = [2, 3, 4] would be valid too, but kind of random.
I would guess a FindPatternNode with no requireds should be a syntax error.
Activity
herwinw commentedon Jun 28, 2024
The same thing can happen with an
ArrayPatternNode:This too gets rejected by MRI
Switching the parser to Prism (ruby 3.4-dev, the default included prism 0.30) results in a segfault.
In this case, MRI even rejects syntax that I would think is not ambiguous:
This still results in a segfault when using
--parser=prismkddnewton commentedon Jun 28, 2024
Thanks @herwinw! I'll get these fixed
[Bug #21345] Fix accepting multiple rest patterns with leading match
[Bug #21345] Fix accepting multiple rest patterns with leading match
[Bug #21345] Fix accepting multiple rest patterns with leading match
[Bug #21345] Fix accepting multiple rest patterns with leading match
[ruby/prism] [Bug #21345] Fix accepting multiple rest patterns with l…