Project

General

Profile

Bug #12984

`rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`

Added by bughit (bug hit) over 2 years ago. Updated 26 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
[ruby-core:78394]

Description

splatting an empty array to a construct that takes a list is suppose to be equivalent to specifying no list

def foo
end

foo *[] #works

so rescue *[] should be equivalent to rescue

begin
  raise 'error' #Uncaught exception
rescue *[]
  puts 'caught'
end

History

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

It's similar to:

super(*[])

Updated by bughit (bug hit) over 2 years ago

Nobuyoshi Nakada wrote:

It's similar to:

super(*[])

I guess there's some similarity. But super has a very explicit definition. Only a naked super is auto-forwarding, any attempt to pass args turns it into manual super. So super(*[]) is equivalent to super(), which makes sense, because by doing super(*array) you are clearly trying to call explicit super.

Updated by bughit (bug hit) over 2 years ago

bug hit wrote:

Nobuyoshi Nakada wrote:

It's similar to:

super(*[])

I guess there's some similarity. But super has a very explicit definition. Only a naked super is auto-forwarding, any attempt to pass args turns it into manual super. So super(*[]) is equivalent to super(), which makes sense, because by doing super(*array) you are clearly trying to call explicit super.

The difference between rescue and super is that there is such a thing as an explicit empty super() that passes nothing, but there is no corresponding explicit empty rescue() that rescues nothing, and so rescue *[] manifests something that isn't supposed to exist.

Updated by jeremyevans0 (Jeremy Evans) 26 days ago

  • Status changed from Open to Closed

This is the expected behavior. rescue *array should mean rescue only exception classes in the array. It should not mean rescue only exception classes in the array, unless the array is empty, in which case rescue StandardError. Otherwise you end up changing the meaning of things like:

exceptions=[]
exceptions << ArgumentError if ENV["ArgumentError"]
begin
  raise ArgumentError, "x"
rescue *exceptions
  puts "caught"
end

Also available in: Atom PDF