Bug #4352: [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent w=
ith eval(s)
http://redmine.ruby-lang.org/issues/show/4352

Author: James M. Lawrence
Status: Open, Priority: Normal
Category: core, Target version: 1.9.x
ruby -v: ruby 1.9.3dev (2011-02-01 trunk 30751) [i386-darwin9.8.0]

def ex_message
  begin
    yield
  rescue =3D> 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>':  (Runti=
meError)
	from /Users/jlawrence/tmp/raiser.rb:7:in `eval'
	from /Users/jlawrence/tmp/raiser.rb:7:in `<main>'


----------------------------------------
http://redmine.ruby-lang.org
ZGlmZiAtLWdpdCBhL2Jvb3RzdHJhcHRlc3QvdGVzdF9ldmFsLnJiIGIvYm9v
dHN0cmFwdGVzdC90ZXN0X2V2YWwucmIKaW5kZXggOWFlNTBhNi4uYzVhYjk1
MyAxMDA2NDQKLS0tIGEvYm9vdHN0cmFwdGVzdC90ZXN0X2V2YWwucmIKKysr
IGIvYm9vdHN0cmFwdGVzdC90ZXN0X2V2YWwucmIKQEAgLTI4Nyw3ICsyODcs
NyBAQCBhc3NlcnRfbm9ybWFsX2V4aXQgJXF7CiAgIGV2YWwoIiIsIG1ldGhv
ZCg6cHJvYykuY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