Actions
Bug #21991
open`$!` stays as the first exception in Ruby Box
Bug #21991:
`$!` stays as the first exception in Ruby Box
Description
Description¶
When Ruby Box is enabled (RUBY_BOX=1), $! inside rescue does not change after the first exception.
$! is expected to show the exception for each rescue block, but it always shows the first one.
Steps to reproduce¶
# test.rb
begin
raise "First error"
rescue
pp $!
end
begin
raise "Second error"
rescue
pp $!
end
begin
raise "Third error"
rescue
pp $!
end
Expected result¶
$ RUBY_BOX=1 ruby test.rb
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See https://docs.ruby-lang.org/en/4.0/Ruby/Box.html for known issues, etc.
#<RuntimeError: First error>
#<RuntimeError: Second error>
#<RuntimeError: Third error>
Actual result¶
$ RUBY_BOX=1 ruby test.rb
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See https://docs.ruby-lang.org/en/4.0/Ruby/Box.html for known issues, etc.
#<RuntimeError: First error>
#<RuntimeError: First error>
#<RuntimeError: First error>
Additional information¶
This issue does not reproduce when RUBY_BOX=1 is not set:
$ ruby test.rb
#<RuntimeError: First error>
#<RuntimeError: Second error>
#<RuntimeError: Third error>
Also, this issue does not reproduce when the exception object is captured explicitly in the rescue clause:
# test.rb
begin
raise "First error"
rescue => e
pp e
end
begin
raise "Second error"
rescue => e
pp e
end
begin
raise "Third error"
rescue => e
pp e
end
$ RUBY_BOX=1 ruby test.rb
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See https://docs.ruby-lang.org/en/4.0/Ruby/Box.html for known issues, etc.
#<RuntimeError: First error>
#<RuntimeError: Second error>
#<RuntimeError: Third error>
Updated by byroot (Jean Boussier) about 4 hours ago
- Related to Bug #21823: $! is nil inside rescue block when $! is accessed before raise in Ruby::Box added
Updated by byroot (Jean Boussier) about 4 hours ago
- Assignee set to tagomoris (Satoshi Tagomori)
Actions