Extra method arguments are magically swallowed after first successful call, possible method cache bug
The following code behaviour totally change since ruby 2.0.0
class Foo def bar(*args) attribute(:bar, *args) end def attribute(name) puts name end end foo = Foo.new begin foo.bar(100) rescue => e puts e.class.name end foo.bar # legit 5.times do foo.bar(100) end puts 'No errors??? WTF???'
ruby < 2.0 output:
ArgumentError bar (eval):3:in `attribute': wrong number of arguments (2 for 1) (ArgumentError) from (eval):3:in `bar' from foo.rb:28 from foo.rb:27:in `times' from foo.rb:27
Which is expected.
But ruby >= 2.0 output
ArgumentError bar bar bar bar bar bar No errors??? WTF???
In short, after the first successful call, the extra arguments are just ignored. I have no idea of what is going on here, but it look like a broken optimization.
All rubies >= 2.0 are affected. 1.8.7 and 1.9.3 are fine.
A gist describing the issue: https://gist.github.com/byroot/9495455
merge revision(s) 45320,45321: [Backport #9622]
* vm_insnhelper.c (vm_callee_setup_arg): turn a macro into an inline function. * vm_insnhelper.c (vm_callee_setup_arg): disable fastpath if splat argument, since argc may differ for each calls. [Bug #9622]
#1 [ruby-core:61427] Updated by nobu (Nobuyoshi Nakada) almost 4 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100