Project

General

Profile

Bug #4352

[patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s)

Added by quix (James M. Lawrence) over 9 years ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.3dev (2011-02-01 trunk 30751) [i386-darwin9.8.0]
Backport:
[ruby-core:35027]
Tags:

Description

=begin
def ex_message
begin
yield
rescue => e
p e.message
end
end

ex_message { eval('raise') }
ex_message { eval('raise', binding) }

eval('def f ; end')
p method(:f).source_location
eval('def g ; end', binding)
p method(:g).source_location


Without patch:
"(eval):1:in `block in ': "
""
["(eval)", 1]
["eval_test.rb", 14]

With patch:
"(eval):1:in block in <main>': "
"(eval):1:in
block in ': "
["(eval)", 1]
["(eval)", 1]

Knowing the line of an error inside eval is useful. Passing a binding
shouldn't discard that information. Present behavior is even wrong:
there's no line 10 in this file.


eval %{

# .. code ...
raise

}, binding


Without patch:
/Users/jlawrence/tmp/raiser.rb:10:in <main>': unhandled exception
from /Users/jlawrence/tmp/raiser.rb:7:in
eval'
from /Users/jlawrence/tmp/raiser.rb:7:in `'

With patch:
/Users/jlawrence/tmp/raiser.rb:7:in eval': (eval):4:in': (RuntimeError)
from /Users/jlawrence/tmp/raiser.rb:7:in eval'
from /Users/jlawrence/tmp/raiser.rb:7:in
'
=end


Files

eval-binding-file-line-4352.patch (11 KB) eval-binding-file-line-4352.patch jeremyevans0 (Jeremy Evans), 07/31/2019 06:39 PM

Related issues

Related to Ruby master - Bug #4487: require_relative fails in an eval'ed fileClosedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Bug #4379: [patch] eval(s, b, "(eval)", n) discards locationClosedko1 (Koichi Sasada)Actions

Also available in: Atom PDF