Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@__DIR__ and @__FILE__ don't expand abspath in run. #26323

Closed
goropikari opened this issue Mar 5, 2018 · 6 comments
Closed

@__DIR__ and @__FILE__ don't expand abspath in run. #26323

goropikari opened this issue Mar 5, 2018 · 6 comments
Labels
macros @macros parser Language parsing and surface syntax regression Regression in behavior compared to a previous version

Comments

@goropikari
Copy link
Contributor

In Julia v0.7, @__DIR__(@__FILE__) doesn't expand to a string with the absolute path to the directory (file) in run.

For example, package MyModule with following structure:
MyModule.jl

module MyModule
export foo, bar, baz, qux

foo() = println(@__DIR__)
bar() = run(`echo $(@__DIR__)`)
baz() = println(@__FILE__)
qux() = run(`echo $(@__FILE__)`)

end
julia> versioninfo()
Julia Version 0.7.0-DEV.4465
Commit f569ebe9bc* (2018-03-04 15:47 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4460T CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
Environment:
  JULIA_SHELL = /usr/bin/zsh

julia> using MyModule

julia> foo()
/home/arch/.julia/v0.7/MyModule/src

julia> bar()
/home/arch/ # Current working directory. This line should be same as foo()
Process(`echo /home/arch/`, ProcessExited(0))

julia> baz()
/home/arch/.julia/v0.7/MyModule/src/MyModule.jl

julia> qux()
none # This should be same as baz()
Process(`echo none`, ProcessExited(0))

I think above behavior is non-intuitive. It is more consistent in v0.6.

julia> versioninfo()
Julia Version 0.6.2
Commit d386e40 (2017-12-13 18:08 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4460T CPU @ 1.90GHz
  WORD_SIZE: 64
  BLAS: libopenblas (HASWELL)
  LAPACK: libopenblas
  LIBM: libm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

julia> using MyModule

julia> foo()
/home/arch/.julia/v0.6/MyModule/src

julia> bar()
/home/arch/.julia/v0.6/MyModule/src

julia> baz()
/home/arch/.julia/v0.6/MyModule/src/MyModule.jl

julia> qux()
/home/arch/.julia/v0.6/MyModule/src/MyModule.jl

Tested on ArchLinux.

@vtjnash vtjnash added the regression Regression in behavior compared to a previous version label Mar 5, 2018
@JeffBezanson
Copy link
Sponsor Member

I believe this is caused by #3150. Since the parser can't see inside the command string, it is not able to insert source location information for the macro call. We can partially work around it by having the cmd macro pass its location info into shell_parse, which can then pass it on to parse. Or we could fully fix #3150.

@goropikari
Copy link
Contributor Author

Why doesn't the problem occur on v0.6?

@JeffBezanson
Copy link
Sponsor Member

The way that @__DIR__ works was also changed.

@goropikari
Copy link
Contributor Author

I understand. Thank you!

@JeffBezanson
Copy link
Sponsor Member

This is still a bug. We only intended to change the implementation of @__DIR__, not its behavior. And because of #3150, the new implementation does not work in this case.

@JeffBezanson JeffBezanson added parser Language parsing and surface syntax macros @macros labels Mar 20, 2018
@simeonschaub
Copy link
Member

Just noticed that this particular issue should be fixed by #37007 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macros @macros parser Language parsing and surface syntax regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

5 participants