Project

General

Profile

Actions

Bug #21132

closed

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

Bug #21132: Changed postposition `rescue` and `if` behavior since Ruby 3.4

Added by watson1978 (Shizuo Fujita) 9 months ago. Updated 9 months 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)

Updated by watson1978 (Shizuo Fujita) 9 months ago Actions #1

  • Description updated (diff)

Updated by watson1978 (Shizuo Fujita) 9 months ago Actions #2

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

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" 

Updated by nobu (Nobuyoshi Nakada) 9 months ago Actions #4

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

  • Assignee set to prism

Updated by hsbt (Hiroshi SHIBATA) 9 months ago Actions #6

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

Updated by watson1978 (Shizuo Fujita) 9 months ago Actions #8

  • Status changed from Open to Closed
Actions

Also available in: PDF Atom