Project

General

Profile

Actions

Bug #9622

closed

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

Bug #9622: Extra method arguments are magically swallowed after first successful call, possible method cache bug

Added by byroot (Jean Boussier) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:61422]

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 2 (0 open2 closed)

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #1 [ruby-core:61427]

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

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.
    [ruby-core:61422] [Bug #9622]

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #2 [ruby-core:61428]

  • 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

Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago Actions #3 [ruby-core:61439]

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

Updated by usa (Usaku NAKAMURA) over 11 years ago Actions #4 [ruby-core:62242]

  • 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.

Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago Actions #5 [ruby-core:62888]

  • 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.

Updated by marcandre (Marc-Andre Lafortune) about 11 years ago Actions #6 [ruby-core:65488]

  • Has duplicate Bug #10291: Strange behaviour of splat in Ruby 2.0.0 added

Updated by nobu (Nobuyoshi Nakada) about 11 years ago Actions #7 [ruby-core:65581]

  • Has duplicate Bug #10353: weird behavior when dynamically adding method using instance_eval added
Actions

Also available in: PDF Atom