Project

General

Profile

Actions

Bug #21132

closed

Changed postposition `rescue` and `if` behavior since Ruby 3.4

Added by watson1978 (Shizuo Fujita) 10 days ago. Updated 9 days ago.

Status:
Closed
Assignee:
Target version:
-
[ruby-core:120962]

Description

When I use postposition rescue and if at same line, the behavior is changed since Ruby 3.4.

Reproduction

def foo
  return "hogehoge" rescue nil if false
  return "fugafuga"
end

foo

Result with Ruby 3.3

irb(main):001> RUBY_VERSION
=> "3.3.6"
irb(main):002* def foo
irb(main):003*   return "hogehoge" rescue nil if false
irb(main):004*   return "fugafuga"
irb(main):005> end
=> :foo
irb(main):006> foo
=> "fugafuga"

YARV bytecode

ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(6,3)>
0000 definemethod                           :foo, foo                 (   1)[Li]
0003 putself                                                          (   6)[Li]
0004 opt_send_without_block                 <calldata!mid:foo, argc:0, FCALL|VCALL|ARGS_SIMPLE>
0006 leave

== disasm: #<ISeq:foo@<compiled>:1 (1,0)-(4,3)>
0000 putstring                              "fugafuga"                (   3)[LiCa]
0002 leave                                                            (   4)[Re]

Result with Ruby 3.4

irb(main):001> RUBY_VERSION
=> "3.4.1"
irb(main):002* def foo
irb(main):003*   return "hogehoge" rescue nil if false
irb(main):004*   return "fugafuga"
irb(main):005> end
=> :foo
irb(main):006> foo
=> "hogehoge"

YARV bytecode

ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,54)>
0000 putself                                                          (   1)[Li]
0001 opt_getconstant_path                   <ic:0 RubyVM::InstructionSequence>
0003 opt_getconstant_path                   <ic:1 DATA>
0005 opt_send_without_block                 <calldata!mid:new, argc:1, ARGS_SIMPLE>
0007 opt_send_without_block                 <calldata!mid:disassemble, argc:0, ARGS_SIMPLE>
0009 opt_send_without_block                 <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE>

Related issues 2 (1 open1 closed)

Related to Ruby master - Bug #21097: `x = a rescue b in c` and `def f = a rescue b in c` parsed differently between parse.y and prismOpenActions
Is duplicate of Ruby master - Bug #21048: [Prism] rescue in modifier form with condition behaves differentlyClosedprismActions
Actions #1

Updated by watson1978 (Shizuo Fujita) 10 days ago

  • Description updated (diff)
Actions #2

Updated by watson1978 (Shizuo Fujita) 10 days ago

  • Subject changed from Changed postposition `resque` and `if` behavior since Ruby 3.4 to Changed postposition `rescue` and `if` behavior since Ruby 3.4

Updated by watson1978 (Shizuo Fujita) 10 days ago

When I switched parser to parse.y, it has same result with Ruby 3.3.

[~/tmp]$ ruby -v --parser=parse.y t.rb
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) [x86_64-linux]
"fugafuga"
[~/tmp]$ ruby -v --parser=prism t.rb
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
"hogehoge"
Actions #4

Updated by nobu (Nobuyoshi Nakada) 10 days ago

  • Related to Bug #21097: `x = a rescue b in c` and `def f = a rescue b in c` parsed differently between parse.y and prism added

Updated by nobu (Nobuyoshi Nakada) 10 days ago

  • Assignee set to prism
Actions #6

Updated by hsbt (Hiroshi SHIBATA) 10 days ago

  • Is duplicate of Bug #21048: [Prism] rescue in modifier form with condition behaves differently added
Actions #8

Updated by watson1978 (Shizuo Fujita) 9 days ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0Like0Like0