Actions
Bug #21608
closed三項演算子と break を組み合わせると SyntaxError
Bug #21608:
三項演算子と break を組み合わせると SyntaxError
ruby -v:
ruby 3.4.6 (2025-09-16 revision dbd83256b1) +PRISM [x86_64-linux]
Description
>> RUBY_VERSION
=> "3.4.6"
>> [1, 2].find {|i| i.even? ? break i : nil }
<internal:kernel>:168:in 'Kernel#loop': (irb):2: syntax error found (SyntaxError)
> 2 | ... i : nil }
| ^ unexpected local variable or method, expecting end-of-input
from /home/ursm/.local/share/mise/installs/ruby/3.4.6/lib/ruby/gems/3.4.0/gems/irb-1.15.2/exe/irb:9:in '<top (required)>'
from /home/ursm/.local/share/mise/installs/ruby/3.4.6/bin/irb:25:in 'Kernel#load'
from /home/ursm/.local/share/mise/installs/ruby/3.4.6/bin/irb:25:in '<main>'
Updated by kddnewton (Kevin Newton) about 1 year ago
- Assignee set to prism
Thank you for the report, I will get this fixed.
Updated by k0kubun (Takashi Kokubun) about 1 year ago
- Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED
Updated by nobu (Nobuyoshi Nakada) about 1 year ago
- Status changed from Open to Rejected
In ruby code, operations with arguments without parentheses have quite lower precedence.
That code is inverting the precedences, so this failure should be an intentional fix.
Updated by Earlopain (Earlopain _) about 1 year ago
To elaborate, if you replace break with a method call, it was already a syntax error. I suspect this was changed with https://bugs.ruby-lang.org/issues/21540. Such code has been rejected since at least ruby 2.0 and was only accidentally accepted since 3.4.0
Updated by k0kubun (Takashi Kokubun) 10 months ago
- Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED to 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
Actions