diff --git a/lib/core/macros.nim b/lib/core/macros.nim index f6ac3aa817..b0f385f022 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -1352,7 +1352,9 @@ proc `$`*(node: NimNode): string = of nnkOpenSymChoice, nnkClosedSymChoice: result = $node[0] of nnkAccQuoted: - result = $node[0] + result = "" + for i in 0 ..< node.len: + result.add(repr(node[i])) else: badNodeKind node, "$" diff --git a/tests/macros/t20067.nim b/tests/macros/t20067.nim new file mode 100644 index 0000000000..0ee3a47123 --- /dev/null +++ b/tests/macros/t20067.nim @@ -0,0 +1,28 @@ +discard """ + output: ''' +b.defaultVal = foo +$c.defaultVal = bar +''' +""" + +import macros + +# #18976 + +macro getString(identifier): string = + result = newLit($identifier) +doAssert getString(abc) == "abc" +doAssert getString(`a b c`) == "abc" + +# #20067 + +template defaultVal*(value : typed) {.pragma.} + +type A = ref object + b {.defaultVal: "foo".}: string + `$c` {.defaultVal: "bar".}: string + +let a = A(b: "a", `$c`: "b") + +echo "b.defaultVal = " & a.b.getCustomPragmaVal(defaultVal) +echo "$c.defaultVal = " & a.`$c`.getCustomPragmaVal(defaultVal)