-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Include statement created by macro doesn't work #8038
Comments
Do not use the node infos since those may be inaccurate or fabricated by the user. For example it is extremely easy common to have literal nodes produced by helper functions in `macros.nim` whose info points to `macros.nim` itself. Fixes nim-lang#7466 Fixes nim-lang#8038
I tested this issue with Nim 1.0.99.
But still the issue is not fixed. |
workaround: use import macros
include "testcode.nim"
dumpTree:
include "testcode.nim"
macro inclMacro(): untyped =
let strLit = newStrLitNode("testcode.nim")
result = quote do:
include `strLit`
echo treeRepr(result)
inclMacro() output:
|
For slurp/gorge/... I noticed the same behavior. In this case I could make it work by setting the lineinfo of generated AST explicitly to the lineinfo of the call site, see here. Maybe this works for include as well. |
callsite doesn't properly work in macros, but year sure that would be a good idea, since workaround sets the lineinfo to the directory of the macro, not the directory of the macro expansion. |
BTW, before you base any logic on this behavior, please also commit some tests that ensure that Nim won't break this behaviour without notice. I have a feeling that there might be a breaking change in the future and nobody would notice it. |
testcode.nim:
inclmacro.nim:
Compiling inclmacro.nim output following error:
Plain include statement in inclmacro.nim works without errors, but calling macro that makes equivalent include statement cause "cannot open" error.
When I use inclMacro macro with absolute path of testcode.nim, above error doesn't happen.
It seems current working directory was changed to somewhere when I use include statement in macro.
The text was updated successfully, but these errors were encountered: