Project

General

Profile

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

Added by Anonymous about 20 hours ago. Updated about 17 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [arm64-darwin25]
[ruby-core:125599]

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

Updated by Kai (kai matsudate) about 20 hours ago Actions #1 [ruby-core:125600]

I'm the reporter. It shows as anonymous due to recreating my account, but I'm following this.

Updated by kddnewton (Kevin Newton) about 17 hours ago Actions #2 [ruby-core:125602]

  • Status changed from Open to Closed

Closed by 9e8ad9ac0489d8390bc11e5b18f4af065d60898c

Actions

Also available in: PDF Atom