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

Kernel#caller from arglist is missing a stack frame #1376

Closed
ghost opened this issue Jan 2, 2014 · 2 comments
Closed

Kernel#caller from arglist is missing a stack frame #1376

ghost opened this issue Jan 2, 2014 · 2 comments
Milestone

Comments

@ghost
Copy link

ghost commented Jan 2, 2014

The spec below (from promise.rb's suite) failed because it asserted the exact position of a stack frame within the backtrace. This broke because, when calling Kernel#caller from a method's arglist (i.e. def fulfill(value = nil, backtrace = caller), JRuby doesn't include that method's stack frame in the backtrace. I worked around that by moving the call into the method's body: lgierth/promise.rb@a3374fa

1) Promise#reject sets the backtrace
     Failure/Error: .to include(__FILE__ + ':' + (__LINE__ - 2).to_s)
       expected "/home/travis/.rvm/gems/jruby-1.7.8-d19/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:114:in `instance_eval'" to include "/home/travis/build/lgierth/promise.rb/spec/promise_spec.rb:387"
     # ./spec/promise_spec.rb:389:in `(root)'
ghost referenced this issue in lgierth/promise.rb Jan 2, 2014
JRuby doesn't execute it within the method's
stack frame, apparantly.
@MSNexploder
Copy link
Contributor

Looks like this is now working just as expected.

require 'pp'

def foo(backtrace = caller)
  pp backtrace
end

def bar(bactrace = nil)
  backtrace ||= caller
  pp backtrace
end

def baz
  foo
  bar
end

baz

Output:

ruby -v
=> jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f Java HotSpot(TM) 64-Bit Server VM 25.91-b14 on 1.8.0_91-b14 [darwin-x86_64]

ruby test.rb
=> ["test.rb:13:in `baz'", "test.rb:17:in `<top>'"]
=> ["test.rb:14:in `baz'", "test.rb:17:in `<top>'"]

@ghost
Copy link
Author

ghost commented Jul 14, 2016

Hey thanks for checking!

cc @dylanahsmith there might be code to be updated somewhere in promise.rb :)

@ghost ghost closed this as completed Jul 14, 2016
@enebo enebo added this to the JRuby 9.1.3.0 milestone Aug 26, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants