Issue #16978 has been updated by jeremyevans0 (Jeremy Evans).


Dan0042 (Daniel DeLorme) wrote in #note-20:
> jeremyevans0 (Jeremy Evans) wrote in #note-16:
> > It's not difficult to make `__FILE__` use `realpath`
> 
> I read this once more a bit more carefully and I think there's a misunderstanding... the idea here is that realpath should be used in `require` _before_ checking if the file is already loaded (and then loading it). So `p->ruby_sourcefile_string` would already be the realpath.

I tried that approach first when working on #17885.  It doesn't work because the loaded feature index is designed around load paths and not real paths.  You would have to rewrite the loaded feature index and its interaction with autoload to switch to that approach.

----------------------------------------
Feature #16978: Ruby should not use realpath for __FILE__
https://bugs.ruby-lang.org/issues/16978#change-92780

* Author: vo.x (Vit Ondruch)
* Status: Open
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
----------------------------------------
This is the simplest test case:

~~~
$ mkdir a

$ echo "puts __FILE__" > a/test.rb

$ ln -s a b

$ ruby -Ib -e "require 'test'"
/builddir/a/test.rb
~~~

This behavior is problematic, because Ruby should not know nothing about the `a` directory. It was not instructed to use it. I should always refer to the file using the original path and do not dig into the underlying details, otherwise depending on file system setup, one might be forced to used `File.realpath` everywhere trying to use `__FILE__`.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>