Hello:
Apparently, expandMacros ignores postfix star * in exportable declarations and instead of producing
let fooStar* = 123 it outputs let fooStar = 123 without *. The following MWE provides the details
## `expandMacros` ignores export postfix `*`
import macros
when false: # keeping for guidance
dumpAstGen:
let fooStar* = 123
macro mfooStar(): untyped =
## expands to
## let fooStar* = 123
result= nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
nnkPostfix.newTree(
newIdentNode("*"),
newIdentNode("fooStar")
),
newEmptyNode(),
newLit(123)
)
)
)
macro mbar: untyped =
## expands to
## let bar = 456
result= nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("bar"),
newEmptyNode(),
newLit(456)
)
)
)
when true:
expandMacros:
mfooStar()
mbar()
echo fooStar
echo bar
The resulting output from compilation 'nim c foo.nim'
let fooStar = 123
let bar = 456
is missing export postfix star '*' after the fooStar symbol.
it happens during the template/macro evaluation of expandMacro's body when it's being turned into a typed parameter. the nnkPostfix(nnkIdent("*"),nnkIdent("fooStar")) gets resolved to nnkSym("fooStar")
getAst(mfooStar()).repr returns the expected string, not sure how much help that is
getAst(mfooStar()).repr returns the expected string, not sure how much help that is
@shirleyquirk: Thanks for a useful suggestion! Now, whenever I want to see what source code my macro call expands to I can do
static:
echo getAst(mfooStar()).repr
instead of a buggy expandMacros.