Project

General

Profile

Bug #21132

Updated by watson1978 (Shizuo Fujita) 10 days ago

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

 ## Reproduction 
 ```ruby 
 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> 
 ```

Back