Forum: Ruby-core [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s)

C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 ko1 (Koichi Sasada) (Guest)
on 2013-02-17 07:27
(Received via mailing list)
Issue #4352 has been updated by ko1 (Koichi Sasada).

Target version changed from 2.0.0 to 2.1.0

Time up for 2.0.0.

Matz, could you check this ticket?

----------------------------------------
Bug #4352: [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent
with eval(s)
https://bugs.ruby-lang.org/issues/4352#change-36402

Author: quix (James M. Lawrence)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.1.0
ruby -v: ruby 1.9.3dev (2011-02-01 trunk 30751) [i386-darwin9.8.0]


=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 <main>': "
 ""
 ["(eval)", 1]
 ["eval_test.rb", 14]

 With patch:
 "(eval):1:in `block in <main>': "
 "(eval):1:in `block in <main>': "
 ["(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 `<main>'

 With patch:
 /Users/jlawrence/tmp/raiser.rb:7:in `eval': (eval):4:in `<main>':
(RuntimeError)
   from /Users/jlawrence/tmp/raiser.rb:7:in `eval'
   from /Users/jlawrence/tmp/raiser.rb:7:in `<main>'
=end
This topic is locked and can not be replied to.