parent
1a9123eb90
commit
685bf944aa
2 changed files with 31 additions and 1 deletions
|
|
@ -1360,7 +1360,9 @@ proc `$`*(node: NimNode): string =
|
||||||
of nnkOpenSymChoice, nnkClosedSymChoice:
|
of nnkOpenSymChoice, nnkClosedSymChoice:
|
||||||
result = $node[0]
|
result = $node[0]
|
||||||
of nnkAccQuoted:
|
of nnkAccQuoted:
|
||||||
result = $node[0]
|
result = ""
|
||||||
|
for i in 0 ..< node.len:
|
||||||
|
result.add(repr(node[i]))
|
||||||
else:
|
else:
|
||||||
badNodeKind node, "$"
|
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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue