Project

General

Profile

Actions

Bug #21048

closed

[Prism] rescue in modifier form with condition behaves differently

Bug #21048: [Prism] rescue in modifier form with condition behaves differently

Added by Earlopain (Earlopain _) 9 months ago. Updated 4 months 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 - Bug #21132: Changed postposition `rescue` and `if` behavior since Ruby 3.4ClosedprismActions

Updated by Earlopain (Earlopain _) 9 months ago Actions #1

  • 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) 9 months ago Actions #2 [ruby-core:120741]

Earlopain (Earlopain _) wrote:

Prism interprets it as (foo rescue nil) if false, not calling the method. parse.y does foo 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 _) 9 months ago Actions #3 [ruby-core:120742]

Yes, I switched it up in the text. Fixed

Updated by Earlopain (Earlopain _) 9 months ago Actions #4

  • Description updated (diff)

Updated by tenderlovemaking (Aaron Patterson) 9 months ago Actions #5 [ruby-core:120751]

  • Assignee set to prism

Updated by kddnewton (Kevin Newton) 9 months ago Actions #6

  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED

Updated by hsbt (Hiroshi SHIBATA) 8 months ago Actions #8

  • Has duplicate Bug #21132: Changed postposition `rescue` and `if` behavior since Ruby 3.4 added

Updated by k0kubun (Takashi Kokubun) 8 months ago Actions #9 [ruby-core:121019]

  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED to 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: DONE

Updated by nagachika (Tomoyuki Chikanaga) 7 months ago Actions #10

  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: DONE to 3.1: DONTNEED, 3.2: DONTNEED, 3.3: REQUIRED, 3.4: DONE

Updated by nagachika (Tomoyuki Chikanaga) 4 months ago Actions #11 [ruby-core:122527]

Backporting c2908613368b2ae404d094a15df61d830fc46dc9 depends on many changesets about prism in ruby_3_3. Please make a backport pull request.

Actions

Also available in: PDF Atom