1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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)
|