Generics with macros can cause some very odd issues, simply due to how generics
work. What is happening here is that the compiler sees the macro is untyped and
attempts to expand it in the declaration resulting in an incorrect behaviour,
we can hack around this by giving the template a typed parameter we disregard:
import std/macros
type MyTemplater = distinct void
template someTemplate(_: typedesc[MyTemplater], body: untyped) =
macro someInnerMacro(innerBody: untyped) {.inject.} =
newCall(ident"echo", newLit(innerBody.repr))
body
proc test[T](x: T) =
someTemplate(MyTemplater):
someInnerMacro y
test 1
Run