Skip to content

Commit e438d0e

Browse files
simeonschaubKristofferC
authored andcommitted
fix #28188: filename lost in cmd interpolation (#37007)
* fix 28188: filename lost in cmd interpolation * move test to test/misc.jl (cherry picked from commit 06b7f0b)
1 parent 625bdf7 commit e438d0e

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

base/cmd.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,5 +386,6 @@ Process(`echo 1`, ProcessExited(0))
386386
```
387387
"""
388388
macro cmd(str)
389-
return :(cmd_gen($(esc(shell_parse(str, special=shell_special)[1]))))
389+
cmd_ex = shell_parse(str, special=shell_special, filename=String(__source__.file))[1]
390+
return :(cmd_gen($(esc(cmd_ex))))
390391
end

base/shell.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function rstrip_shell(s::AbstractString)
1616
end
1717

1818
function shell_parse(str::AbstractString, interpolate::Bool=true;
19-
special::AbstractString="")
19+
special::AbstractString="", filename="none")
2020
s::SubString = SubString(str, firstindex(str))
2121
s = rstrip_shell(lstrip(s))
2222

@@ -69,7 +69,8 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
6969
# string interpolation syntax (see #3150)
7070
ex, j = :var, stpos+3
7171
else
72-
ex, j = Meta.parse(s,stpos,greedy=false)
72+
# use parseatom instead of parse to respect filename (#28188)
73+
ex, j = Meta.parseatom(s, stpos, filename=filename)
7374
end
7475
last_parse = (stpos:prevind(s, j)) .+ s.offset
7576
update_arg(ex);

test/misc.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,8 @@ end
830830
@testset "fieldtypes Module" begin
831831
@test fieldtypes(Module) isa Tuple
832832
end
833+
834+
835+
@testset "issue #28188" begin
836+
@test `$(@__FILE__)` == let file = @__FILE__; `$file` end
837+
end

0 commit comments

Comments
 (0)