Actions
Bug #22089
closed
Prism accepts statement modifiers in if/unless/elsif conditions that parse.y rejects
Bug #22089:
Prism accepts statement modifiers in if/unless/elsif conditions that parse.y rejects
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [arm64-darwin25]
Description
The following is accepted by Prism but rejected by parse.y:
$ ruby -cve "if a if b then end"
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [arm64-darwin25]
Syntax OK
$ ruby --parser=parse.y -cve "if a if b then end"
ruby 4.0.0 (2025-12-25 revision 553f1675f3) [arm64-darwin25]
-e:1: syntax error, unexpected 'if' modifier, expecting 'then' or '\n' or ';'
if a if b then end
^~
ruby: compile error (SyntaxError)
The same applies to other statement modifiers (unless/while/until) and to unless/elsif conditions. For example, all of the following are accepted by Prism but rejected by parse.y:
if a if b then end
if a unless b then end
if a while b then end
if a until b then end
unless a until b then end
if x then elsif a if b then end
I can also reproduce this on Prism's main branch (1.9.0).
Prism already treats the same syntax as a syntax error in while/until conditions, so it looks like if/unless/elsif conditions should reject it as well, matching both parse.y and Prism's own handling of while/until conditions.
I have a draft patch here: https://github.com/ruby/prism/pull/4120
Actions