Actions
Bug #20917
openredo/next in nested begin block causes wrong order of execution
Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-darwin24]
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:
puts 0
puts 1
puts 2
redo
- unwind to nested
ensure
block puts 3
- unwind to outer
ensure
block puts 4
break
- end of loop
Interestingly enough, if we add an empty rescue
block before any of the ensure
blocks, then the execution order is correct.
Updated by Eregon (Benoit Daloze) 6 days ago
Indeed, it seems like a bug, I think as well the "redo jump/unwind/exception" should run ensure's and get to the "break jump/unwind/exception" which should override the redo
like when a Ruby exception overrides another.
FWIW, this is 0 1 2 3 4
on both TruffleRuby and JRuby.
Updated by kddnewton (Kevin Newton) 2 days ago
Agreed this is a bug. For additional context, this is the same on parse.y and prism.
Actions
Like0
Like0Like0