Project

General

Profile

Bug #5330

Bug Report: wrong backtrace

Added by ulrich (Ulrich Kramer) almost 9 years ago. Updated over 6 years ago.

Status:
Rejected
Priority:
Normal
Target version:
-
ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
Backport:
[ruby-core:39572]

Description

=begin
I would like to report a ruby1.9 bug. I tried to create a new ticket in redmine. After registration(wonderix) I tried to login, but I didn't succeed. After 4 password resets I gave up.

So here is my description:

a.rb:
test = Class.new(Object)
test.class_eval(File.read("b.rb"),"b.rb",1)
test.run

b.rb:
p caller
def self.run()
p caller
end

When I run a.rb I got:
["a.rb:2:in class_eval'", "a.rb:2:in'"]
["a.rb:3:in `'"]

Should be:
["b.rb:1:in class_eval'", "a.rb:2:in'"]
["b.rb:3:in `'"]

ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]

Mit freundlichen Grüßen | best regards,

Ulrich Kramer
Senior Developer
=end

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • ruby -v changed from - to ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
#2

Updated by ko1 (Koichi Sasada) over 8 years ago

  • Assignee set to akr (Akira Tanaka)
#3

Updated by shyouhei (Shyouhei Urabe) over 8 years ago

  • Status changed from Open to Assigned

Updated by akr (Akira Tanaka) over 6 years ago

  • Status changed from Assigned to Rejected

Ulrich Kramer wrote:

a.rb:
test = Class.new(Object)
test.class_eval(File.read("b.rb"),"b.rb",1)
test.run

b.rb:
p caller
def self.run()
p caller
end

When I run a.rb I got:
["a.rb:2:in class_eval'", "a.rb:2:in'"]
["a.rb:3:in `'"]

Should be:
["b.rb:1:in class_eval'", "a.rb:2:in'"]
["b.rb:3:in `'"]

No.

caller() doesn't return the current stack frame unless 0 is specified as the argument.

caller() returns an array which contains the caller stack frame and ancestor stack frames.
caller of the top level of b.rb is test.class_eval described in a.rb.
caller of "run" method is the top level of a.rb.

caller(0) makes things clear.

% cat a.rb
test = Class.new(Object)
test.class_eval(File.read("b.rb"),"b.rb",1)
test.run
% cat b.rb
p caller(0)
def self.run()
  p caller(0)
end
% ./ruby a.rb                               
["b.rb:1:in `<main>'", "a.rb:2:in `class_eval'", "a.rb:2:in `<main>'"]
["b.rb:3:in `run'", "a.rb:3:in `<main>'"]

b.rb:1 and b.rb:3 appears as the first element (current stack frame).
The second element shows the stack frame in a.rb.

Also available in: Atom PDF