Project

General

Profile

Actions

Bug #20917

open

redo/next in nested begin block causes wrong order of execution

Added by hoshiumiarata (Arata Hoshiumi) 21 days ago. Updated 16 days ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-darwin24]
[ruby-core:120034]

Description

It seems that redo/next in a nested begin block can cause the wrong order of execution.
For example:

for _ in [0]
  puts 0
  begin
    puts 1
    begin
      puts 2
      redo
    ensure
      puts 3
    end
  ensure
    puts 4
    break
  end
end

It prints:

0
1
2
3
4
3
4
=> nil

But I think it should print:

0
1
2
3
4
=> nil

Because execution order should be:

  1. puts 0
  2. puts 1
  3. puts 2
  4. redo
  5. unwind to nested ensure block
  6. puts 3
  7. unwind to outer ensure block
  8. puts 4
  9. break
  10. end of loop

Interestingly enough, if we add an empty rescue block before any of the ensure blocks, then the execution order is correct.

Actions

Also available in: Atom PDF

Like0
Like0Like0