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
lgierth opened this Issue Jan 2, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@lgierth

lgierth 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)'

lgierth referenced this issue in lgierth/promise.rb Jan 2, 2014

Don't gather backtrace within arglist
JRuby doesn't execute it within the method's
stack frame, apparantly.
@MSNexploder

This comment has been minimized.

Show comment
Hide comment
@MSNexploder

MSNexploder Jul 14, 2016

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>'"]
Contributor

MSNexploder commented Jul 14, 2016

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>'"]
@lgierth

This comment has been minimized.

Show comment
Hide comment
@lgierth

lgierth Jul 14, 2016

Hey thanks for checking!

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

lgierth commented Jul 14, 2016

Hey thanks for checking!

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

@lgierth lgierth closed this Jul 14, 2016

@enebo enebo added this to the JRuby 9.1.3.0 milestone Aug 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment