From daba6d935fa1b7e3ce84081be74018a5af698afc Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Fri, 30 Oct 2020 16:59:56 +0800 Subject: [PATCH] closes #7374 (#15781) * add testcase for #7374 * minor * fix test (cherry picked from commit 1725db9295b037ac410f0e6d48952c01218aee89) --- tests/template/tshadow.nim | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/template/tshadow.nim diff --git a/tests/template/tshadow.nim b/tests/template/tshadow.nim new file mode 100644 index 0000000000..a4de715924 --- /dev/null +++ b/tests/template/tshadow.nim @@ -0,0 +1,29 @@ +discard """ + output: '''fish +fish''' +""" + +import macros + +block: + template init(initHook: proc(s: string)) = + proc dostuff = + var s = "fish" + initHook(s) + dostuff() + + init do(s: string): + echo s + +block: + macro init(initHook: proc(s: string)) = + result = newStmtList( + newProc(name = ident("dostuff"), body = newStmtList( + newVarStmt(ident("s"), newStrLitNode("fish")), + newCall(initHook, ident("s")) + )), + newCall("dostuff") + ) + + init proc(s: string) = + echo s