Fix macro expansion in expandMacros (#8998)
* Fix macro expansion in expandMacros Running a semanticized node trough the semantic pass was a bad idea. Fixes #7723 * Simpler smaller implementation
This commit is contained in:
parent
98a8868cb4
commit
32d5b80938
2 changed files with 22 additions and 5 deletions
|
|
@ -1275,7 +1275,7 @@ proc boolVal*(n: NimNode): bool {.compileTime, noSideEffect.} =
|
||||||
if n.kind == nnkIntLit: n.intVal != 0
|
if n.kind == nnkIntLit: n.intVal != 0
|
||||||
else: n == bindSym"true" # hacky solution for now
|
else: n == bindSym"true" # hacky solution for now
|
||||||
|
|
||||||
macro expandMacros*(body: typed): untyped =
|
macro expandMacros*(body: typed): typed =
|
||||||
## Expands one level of macro - useful for debugging.
|
## Expands one level of macro - useful for debugging.
|
||||||
## Can be used to inspect what happens when a macro call is expanded,
|
## Can be used to inspect what happens when a macro call is expanded,
|
||||||
## without altering its result.
|
## without altering its result.
|
||||||
|
|
@ -1294,10 +1294,8 @@ macro expandMacros*(body: typed): untyped =
|
||||||
## will actually dump `x + y`, but at the same time will print at
|
## will actually dump `x + y`, but at the same time will print at
|
||||||
## compile time the expansion of the ``dump`` macro, which in this
|
## compile time the expansion of the ``dump`` macro, which in this
|
||||||
## case is ``debugEcho ["x + y", " = ", x + y]``.
|
## case is ``debugEcho ["x + y", " = ", x + y]``.
|
||||||
template inner(x: untyped): untyped = x
|
echo body.toStrLit
|
||||||
|
result = body
|
||||||
result = getAst(inner(body))
|
|
||||||
echo result.toStrLit
|
|
||||||
|
|
||||||
proc customPragmaNode(n: NimNode): NimNode =
|
proc customPragmaNode(n: NimNode): NimNode =
|
||||||
expectKind(n, {nnkSym, nnkDotExpr, nnkBracketExpr, nnkTypeOfExpr, nnkCheckedFieldExpr})
|
expectKind(n, {nnkSym, nnkDotExpr, nnkBracketExpr, nnkTypeOfExpr, nnkCheckedFieldExpr})
|
||||||
|
|
|
||||||
19
tests/macros/t7723.nim
Normal file
19
tests/macros/t7723.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
discard """
|
||||||
|
msg: '''
|
||||||
|
proc init(foo128049: int; bar128051: typedesc[int]): int =
|
||||||
|
foo128049
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
macro foo1(): untyped =
|
||||||
|
result = newStmtList()
|
||||||
|
result.add quote do:
|
||||||
|
proc init(foo: int, bar: typedesc[int]): int =
|
||||||
|
foo
|
||||||
|
|
||||||
|
expandMacros:
|
||||||
|
foo1()
|
||||||
|
|
||||||
|
doAssert init(1, int) == 1
|
||||||
Loading…
Add table
Add a link
Reference in a new issue