Bug #9622

Extra method arguments are magically swallowed after first successful call, possible method cache bug

Added by Jean Boussier over 1 year ago. Updated about 1 year ago.

[ruby-core:61422]
Status:Closed
Priority:Normal
Assignee:-
ruby -v:2.0.0 Backport:1.9.3: REQUIRED, 2.0.0: DONE, 2.1: DONE

Description

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.

Regards.

A gist describing the issue: https://gist.github.com/byroot/9495455


Related issues

Duplicated by Ruby trunk - Bug #10291: Strange behaviour of splat in Ruby 2.0.0 Closed 09/24/2014
Duplicated by Ruby trunk - Bug #10353: weird behavior when dynamically adding method using instance_eval Closed 10/10/2014

Associated revisions

Revision 45321
Added by Nobuyoshi Nakada over 1 year ago

vm_insnhelper.c: disable fastpath if splat

  • vm_insnhelper.c (vm_callee_setup_arg): disable fastpath if splat argument, since argc may differ for each calls. [Bug #9622]

Revision 45321
Added by Nobuyoshi Nakada over 1 year ago

vm_insnhelper.c: disable fastpath if splat

  • vm_insnhelper.c (vm_callee_setup_arg): disable fastpath if splat argument, since argc may differ for each calls. [Bug #9622]

Revision 45748
Added by Usaku NAKAMURA about 1 year ago

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]

Revision 46302
Added by Tomoyuki Chikanaga about 1 year ago

merge revision(s) r45320,r45321: [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]

History

#1 Updated by Nobuyoshi Nakada over 1 year ago

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

Applied in changeset r45321.


vm_insnhelper.c: disable fastpath if splat

  • vm_insnhelper.c (vm_callee_setup_arg): disable fastpath if splat argument, since argc may differ for each calls. [Bug #9622]

#2 Updated by Nobuyoshi Nakada over 1 year ago

  • Priority changed from 5 to Normal
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED

#3 Updated by Tomoyuki Chikanaga over 1 year ago

just for memorandum. r45320 is also required to be backported.

#4 Updated by Usaku NAKAMURA about 1 year ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED to 1.9.3: REQUIRED, 2.0.0: DONE, 2.1: REQUIRED

backported into ruby_2_0_0 at r45748.

#5 Updated by Tomoyuki Chikanaga about 1 year ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: DONE, 2.1: REQUIRED to 1.9.3: REQUIRED, 2.0.0: DONE, 2.1: DONE

Backported into ruby_2_1 at r46302.

#6 Updated by Marc-Andre Lafortune 9 months ago

  • Duplicated by Bug #10291: Strange behaviour of splat in Ruby 2.0.0 added

#7 Updated by Nobuyoshi Nakada 9 months ago

  • Duplicated by Bug #10353: weird behavior when dynamically adding method using instance_eval added

Also available in: Atom PDF