diff options
author | LemonBoy <LemonBoy@users.noreply.github.com> | 2018-10-09 23:24:54 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-10-09 23:24:54 +0200 |
commit | 32d5b80938daa3c4983aed5836a022804ff28cce (patch) | |
tree | eb5f0867ba4ee1b36be92de0eaf04140fbc8b631 | |
parent | 98a8868cb43efca008a909178b3475d163847833 (diff) | |
download | Nim-32d5b80938daa3c4983aed5836a022804ff28cce.tar.gz |
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
-rw-r--r-- | lib/core/macros.nim | 8 | ||||
-rw-r--r-- | tests/macros/t7723.nim | 19 |
2 files changed, 22 insertions, 5 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 5e4b9d8c9..971c00012 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -1275,7 +1275,7 @@ proc boolVal*(n: NimNode): bool {.compileTime, noSideEffect.} = if n.kind == nnkIntLit: n.intVal != 0 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. ## Can be used to inspect what happens when a macro call is expanded, ## 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 ## compile time the expansion of the ``dump`` macro, which in this ## case is ``debugEcho ["x + y", " = ", x + y]``. - template inner(x: untyped): untyped = x - - result = getAst(inner(body)) - echo result.toStrLit + echo body.toStrLit + result = body proc customPragmaNode(n: NimNode): NimNode = expectKind(n, {nnkSym, nnkDotExpr, nnkBracketExpr, nnkTypeOfExpr, nnkCheckedFieldExpr}) diff --git a/tests/macros/t7723.nim b/tests/macros/t7723.nim new file mode 100644 index 000000000..e1d0a8a8d --- /dev/null +++ b/tests/macros/t7723.nim @@ -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 |