Bug #2782

Binding#eval not completely indicative of its binding

Added by Thomas Sawyer almost 2 years ago. Updated 10 months ago.

[ruby-core:28307]
Status:Closed Start date:02/23/2010
Priority:Normal Due date:
Assignee:Yusuke Endoh % Done:

0%

Category:-
Target version:1.9.2
ruby -v:

Description

binding.eval("__FILE__") does not return the file from which the binding was created.

Given the purpose of binding it should hold that:

  __FILE__ == binding.eval("__FILE__")

Related issues

duplicated by ruby-trunk - Bug #1769: eval with binding, without location Closed

Associated revisions

Revision 27716
Added by Yusuke Endoh almost 2 years ago

* vm_eval.c (eval_string_with_cref): propagative filename and line_no of binding. [ruby-dev:38767] [ruby-core:28307] * vm_core.h (rb_binding_t), proc.c: add filename and line_no fields to preserve them.

History

Updated by Ryan Davis almost 2 years ago

On Feb 23, 2010, at 05:18 , Thomas Sawyer wrote:

> Bug #2782: Binding#eval not completely indicative of its binding
> http://redmine.ruby-lang.org/issues/show/2782
> 
> Author: Thomas Sawyer
> Status: Open, Priority: Normal
> Category: core
> ruby -v: 1.9.1
> 
> binding.eval("__FILE__") does not return the file from which the binding was created.
> 
> Given the purpose of binding it should hold that:
> 
>  __FILE__ == binding.eval("__FILE__")

Just my two cents: (yen?)

__FILE__ is expanded at parse time directly into the parse tree. As such, it isn't really a variable or a constant, just a placeholder. I don't think it is going to be easy to make it act like a constant for Binding#eval.

Updated by Yusuke Endoh almost 2 years ago

  • Assignee set to Yukihiro Matsumoto
Hi,

2010/2/23 Thomas Sawyer <redmine@ruby-lang.org>:
> binding.eval("__FILE__") does not return the file from which the binding was created.
>
> Given the purpose of binding it should hold that:
>
>   __FILE__ == binding.eval("__FILE__")


In the current semantics, I guess binding does not includes
the imformation of filename and lineno.

At least, this is not a bug.  I moved the ticket to Feature
tracker.

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

Updated by Yusuke Endoh almost 2 years ago

  • Target version set to 3.0

Updated by Yusuke Endoh almost 2 years ago

  • Assignee changed from Yukihiro Matsumoto to Yusuke Endoh
  • Target version changed from 3.0 to 1.9.2
Hi,

2010/4/11 Yusuke Endoh <redmine@ruby-lang.org>:
> 2010/2/23 Thomas Sawyer <redmine@ruby-lang.org>:
>> binding.eval("__FILE__") does not return the file from which the binding was created.
>>
>> Given the purpose of binding it should hold that:
>>
>>   __FILE__ == binding.eval("__FILE__")
>
>
> In the current semantics, I guess binding does not includes
> the imformation of filename and lineno.
>
> At least, this is not a bug. ?I moved the ticket to Feature
> tracker.


Sorry I was wrong.  I didn't know 1.8 preserves the filename.
I agree that this is a bug.

And this ticket duplicates #1769.  I've suggested a patch in that ticket.

-- 
Yusuke Endoh <mame@tsg.ne.jp>

Updated by Yusuke Endoh almost 2 years ago

  • Status changed from Open to Closed
This issue was solved with changeset r27716.
Yuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Also available in: Atom PDF