Project

General

Profile

Actions

Bug #21048

closed

[Prism] rescue in modifier form with condition behaves differently

Added by Earlopain (Earlopain _) about 1 month ago. Updated 9 days ago.

Status:
Closed
Assignee:
Target version:
-
ruby -v:
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
[ruby-core:120738]

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

Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #21132: Changed postposition `rescue` and `if` behavior since Ruby 3.4ClosedprismActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0