[ruby-core:76849] [Ruby trunk Bug#12568] wrong ArgumentError if an array is given for instance_exec with optional argument
From:
usa@...
Date:
2016-08-12 02:50:59 UTC
List:
ruby-core #76849
Issue #12568 has been updated by Usaku NAKAMURA.
Backport changed from 2.1: DONTNEED, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: DONTNEED, 2.2: DONE, 2.3: REQUIRED
ruby_2_2 r55875 merged revision(s) 55609.
----------------------------------------
Bug #12568: wrong ArgumentError if an array is given for instance_exec with optional argument
https://bugs.ruby-lang.org/issues/12568#change-60073
* Author: Yui NARUSE
* Status: Closed
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.4.0dev (2016-07-08 trunk 55607) [x86_64-darwin15]
* Backport: 2.1: DONTNEED, 2.2: DONE, 2.3: REQUIRED
----------------------------------------
From Ruby 2.2 to trunk, it wrongly raise ArgumentError as follows:
Sample code:
```ruby
instance_exec([1,2,3]){|a| p a}
instance_exec([1,2,3]){|a=[]| p a}
instance_exec([1,2,3], &->(a){ p a })
->(a=[]){ p a }.to_proc.call([1,2,3])
instance_exec([1,2,3], &->(a=[]){ p a })
```
Expected result:
```
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
```
Actual result:
```
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
test.rb:7:in `block in <main>': wrong number of arguments (given 3, expected 0..1) (ArgumentError)
from test.rb:7:in `instance_exec'
from test.rb:7:in `<main>'
```
This issue affect https://github.com/rails/rails/pull/25699
--
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>