Actions
Bug #21048
open[Prism] rescue in modifier form with condition behaves differently
Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
Description
With the following code there is a discrepancy in how prism and parse.y consider precedence:
$called = false
def foo
$called = true
end
foo rescue nil if false
puts "Called: #{$called}"
Prism interprets it as foo rescue (nil if false)
, calling the method. parse.y
does (foo rescue nil) if false
since at least Ruby 2.0
$ ruby -v
ruby 3.5.0dev (2025-01-19T12:44:20Z master f27ed98eff) +PRISM [x86_64-linux]
$ ruby code.rb
Called: true
$ ruby --parser=parse.y code.rb
Called: false
Updated by Earlopain (Earlopain _) 2 days ago
- ruby -v changed from 3.4.1 to ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
Updated by nobu (Nobuyoshi Nakada) 1 day ago
Earlopain (Earlopain _) wrote:
Prism interprets it as
(foo rescue nil) if false
, not calling the method.parse.y
doesfoo rescue (nil if false)
since at least Ruby 2.0
Inverse?
$ ruby -v ruby 3.5.0dev (2025-01-19T12:44:20Z master f27ed98eff) +PRISM [x86_64-linux] $ ruby code.rb Called: true $ ruby --parser=parse.y code.rb Called: false
Updated by Earlopain (Earlopain _) 1 day ago
Yes, I switched it up in the text. Fixed
Actions
Like0
Like0Like0Like0Like0