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 about 1 year 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

Also available in: Atom PDF