From 2a31f42d35121e12dfbef368ce9d5d1751aa1376 Mon Sep 17 00:00:00 2001 From: alaviss Date: Tue, 9 Oct 2018 20:53:13 +0700 Subject: [PATCH] asyncmacro: add nnkSym support for getName() (#9204) Fixes #9201 --- lib/pure/asyncmacro.nim | 2 +- tests/async/t9201.nim | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/async/t9201.nim diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index 9acd4bd795..b18d20d554 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -190,7 +190,7 @@ proc getName(node: NimNode): string {.compileTime.} = case node.kind of nnkPostfix: return node[1].strVal - of nnkIdent: + of nnkIdent, nnkSym: return node.strVal of nnkEmpty: return "anonymous" diff --git a/tests/async/t9201.nim b/tests/async/t9201.nim new file mode 100644 index 0000000000..5aaba70637 --- /dev/null +++ b/tests/async/t9201.nim @@ -0,0 +1,14 @@ +discard """ + exitcode: 0 +""" + +# Derived from issue #9201 +import asyncdispatch, macros + +macro newAsyncProc(name: untyped): untyped = + expectKind name, nnkStrLit + let pName = genSym(nskProc, name.strVal) + result = getAst async quote do: + proc `pName`() = discard + +newAsyncProc("hello")