mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
(cherry picked from commit 685bf944aa)
This commit is contained in:
@@ -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, "$"
|
||||
|
||||
|
||||
28
tests/macros/t20067.nim
Normal file
28
tests/macros/t20067.nim
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user