Project

General

Profile

Backport #146

Incorrect line numbers in "caller" output when evaluated in a Proc binding

Added by wilson (Wilson Bilkovich) about 12 years ago. Updated 12 months ago.

Status:
Closed
Priority:
Normal
[ruby-core:17234]

Description

=begin
The second frame's line number appears to always be incorrect when a Proc is created via a non-toplevel method call.
This small program and its output illustrate the issue:

def first # line 1 of proc_caller.rb on my system
second
end

def second
b = third do
1 + 1
end
return b
end

def third(&b)
return b
end

eval("p caller(0)", first)

Output on recent 1.8 releases, including 1.8.6 and 1.8.7:
["proc_caller.rb:6:in second'", "proc_caller.rb:6:infirst'", "proc_caller.rb:16"]

Output that I would expect: (line 6 is in 'second', not 'first')
["proc_caller.rb:6:in second'", "proc_caller.rb:2:infirst'", "proc_caller.rb:16"]
=end

#1

Updated by wilson (Wilson Bilkovich) almost 12 years ago

=begin
Everybody agrees that this is a bug, right?
=end

#2

Updated by shyouhei (Shyouhei Urabe) over 11 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

=begin

=end

#3

Updated by runpaint (Run Paint Run Run) almost 11 years ago

=begin
On 1.9 trunk:

 ["(eval):1:in `second'", "/tmp/proc_caller.rb:16:in `eval'", "/tmp/proc_caller.rb:16:in `<main>'"]

(I'm trying to understand the changes in caller output between 1.8 and 1.9 and failing).
=end

#4

Updated by marcandre (Marc-Andre Lafortune) almost 11 years ago

  • Category set to core
  • ruby -v set to -

=begin
The expected output should be the same for
eval("p caller(0)", first.binding)
and
eval("p caller(0)", second.binding)
since the block has the same binding (i.e. that of second).

At the moment "p caller" is evaluated, both first and second have returned, so the output should not contain "proc_caller.rb:6". In neither case should we expect to see "proc_caller.rb:2:in `first'" in the backtrace.

It appears that when a block is captured (here by third), the binding is set the the full stack instead of just that of second. This leads to a longer backtrace, as seen with the output of caller or if an exception is raised in the eval.

Just to confirm that this bug is not present in Ruby 1.9; the output is quite sensible and the same from both first.binding and second.binding.
=end

#5

Updated by shyouhei (Shyouhei Urabe) almost 10 years ago

  • Status changed from Open to Assigned

=begin

=end

#6

Updated by jeremyevans0 (Jeremy Evans) 12 months ago

  • ruby -v deleted (-)
  • Status changed from Assigned to Closed
  • Description updated (diff)
  • Project changed from Ruby 1.8 to Backport187
  • Tracker changed from Bug to Backport

Also available in: Atom PDF