Skip to content

Multi-rescue should not eagerly evaluate its elements #5538

@headius

Description

@headius

When rescuing multiple exceptions, they appear to be evaluated only if needed. For example:

[] ~/projects/rubygems $ ruby -v -e 'begin; raise; rescue StandardError, DumbError; p :here; end'
jruby 9.2.6.0-SNAPSHOT (2.5.3) 2018-12-21 65a4b42 Java HotSpot(TM) 64-Bit Server VM 25.181-b13 on 1.8.0_181-b13 +jit [darwin-x86_64]
NameError: uninitialized constant DumbError
  const_missing at org/jruby/RubyModule.java:3536
         <main> at -e:1

[] ~/projects/rubygems $ rvm ruby-2.5.3 do ruby -v -e 'begin; raise; rescue StandardError, DumbError; p :here; end'
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]
:here

DumbError does not exist, and yet the rescue handles StandardError properly.

I found this attempting to run RubyGems tests; they disable gems and then have a rescue block like this:

begin
  gem 'minitest', '~> 5.0'
rescue NoMethodError, Gem::LoadError
  # for ruby tests
end

We raise a NameError for the Gem reference here, and MRI does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions