[ruby-core:94868] [Ruby master Bug#12984] `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`

From: bughit.github@...
Date: 2019-09-09 17:16:04 UTC
List: ruby-core #94868
Issue #12984 has been updated by bughit (bug hit).


>  I think it's is less surprising than rescue *no_classes to "magically" rescue StandardError

It is the current behavior that's magical. If you try to deduce what `rescue *[]` means from the primitives, it goes like this:

- `*[]` means a void (non-existent) list
- therefore `rescue *[]` means `rescue`. It can't mean `rescue()` (like `super()`) because `rescue()` does not exist

Anything but the above is special-casing, i.e. magic

----------------------------------------
Bug #12984: `rescue *[]` should be equivalent to `rescue` as `method_call(*[])` is equivalent to `method_call`
https://bugs.ruby-lang.org/issues/12984#change-81485

* Author: bughit (bug hit)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
* ruby -v: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
Splatting an empty array to a construct that takes a list is supposed to be equivalent to specifying no list

```ruby
def foo
end

foo *[] #works
```

So `rescue *[]` should be equivalent to `rescue`

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




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next