#caller returns `__send__' as one of the callers #603

Closed
lkfken opened this Issue Mar 25, 2013 · 2 comments

Projects

None yet

2 participants

@lkfken
lkfken commented Mar 25, 2013
require 'pp'

module A
  def method_from_a
    caller
  end
end

class C
  include A
  def method_from_c
    __send__(:method_from_a)
  end
end

pp C.new.method_from_c

The code above if run under MRI Ruby 1.9.3 or 2.0, the output is:

["X:/ene/RubyScripts/1development/debug_caller/caller.rb:12:in `method_from_c'",
 "X:/ene/RubyScripts/1development/debug_caller/caller.rb:16:in `<top (required)>'",
 "-e:1:in `load'",
 "-e:1:in `<main>'"]

If the code above is running under JRuby 1.7.3, the output is:

["X:/ene/RubyScripts/1development/debug_caller/caller.rb:12:in `__send__'",
 "X:/ene/RubyScripts/1development/debug_caller/caller.rb:12:in `method_from_c'",
 "X:/ene/RubyScripts/1development/debug_caller/caller.rb:16:in `(root)'",
 "-e:1:in `load'",
 "-e:1:in `(root)'"]

The output from MRI Ruby and JRuby are obviously different.

I could add some additional logic to my code using something like RUBY_PLATFORM to find the immediate caller, but isn't a compatibility issue for JRUBY?

@lkfken
lkfken commented Mar 25, 2013

Also, if I change the method to

...
module A
  def method_from_a(key = caller)
    key
  end
end
...

MRI Ruby (both 1.9.3 and 2.0) will produce the same output (as in previous example).
But JRuby will produce a different output.

["X:/ene/RubyScripts/1development/debug_caller/caller.rb:12:in `method_from_c'",
 "X:/ene/RubyScripts/1development/debug_caller/caller.rb:16:in `(root)'",
 "-e:1:in `load'",
 "-e:1:in `(root)'"]

and this is the same (well...not exactly if compare it word by word) output as in MRI Ruby 1.9.3 or 2.0.

So apparently, JRuby's #caller will not include #send as one of the callers if it is invoked at the parameter.

@BanzaiMan
Member

On master, the output is:

["gh-603.rb:12:in `method_from_c'", "gh-603.rb:16:in `(root)'"]
@BanzaiMan BanzaiMan closed this Sep 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment