@__DIR__ doesn't work properly within backtick `...` notation

Consider the following script:

# this is correct:

# but this is not, it's just the cwd:
run(`echo $(@__DIR__)`)

# but this works:
foo = @__DIR__
run(`echo $foo`)

I get


which defies all logic to me.

Why does @__DIR__ have a different value when used in backtick notation?

This should be fixed by https://github.com/JuliaLang/julia/pull/37007. Your example should work as expected on master.