Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect receiving of arguments in RPC methods (due to Ruby 2.2.1 bug) #1

Closed
TeWu opened this issue Sep 23, 2015 · 1 comment
Closed
Assignees
Labels

Comments

@TeWu
Copy link
Owner

TeWu commented Sep 23, 2015

RPC methods are defined dynamically like (gen.rb:38):

define_method method_name do |*args, **kwargs|

Due to Ruby 2.2.1 bug, arguments are not received as they ware passed to method, when:

  • Method is defined using define_method.
  • Method parameter list contain both *args and **kwargs.
  • Method is contained in class that also contain method_missing method.

All of that requirements are fulfilled for RPC methods, which can result in situations when arguments are not received as they ware passed to those methods.

Ruby 2.2.1 argument passing bug

Minimal example:

class A
  def method_missing(method, *args, **kwargs, &block)
    super
  end
end

A.instance_eval do
  define_method "m" do |*args, **kwargs|
    p args
  end
end

a1 = A.new
a2 = A.new

a1.m(1, 2.0, "trzy", a2) #=> [nil, 1, [], {}]

a1.m(1, 2.0, "trzy", a2) prints [nil, 1, [], {}], but should print [1, 2.0, "trzy", #<A:0x000000013f50d8>].
This bug is non-existent in Ruby 2.1.5 and fixed in Ruby 2.3.0dev. Hopefully the path will be backported to 2.2 when 2.3 is released.

@TeWu TeWu added the bug label Sep 23, 2015
@TeWu TeWu self-assigned this Sep 23, 2015
@TeWu
Copy link
Owner Author

TeWu commented Sep 23, 2015

The bug only manifest itself when last argument passed to m is A's instance.
Which means that the correct output can be obtained by calling a1.m(1, 2.0, "trzy", a2, {}) instead of a1.m(1, 2.0, "trzy", a2).

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant