t20067.nim 543 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. output: '''
  3. b.defaultVal = foo
  4. $c.defaultVal = bar
  5. '''
  6. """
  7. import macros
  8. # #18976
  9. macro getString(identifier): string =
  10. result = newLit($identifier)
  11. doAssert getString(abc) == "abc"
  12. doAssert getString(`a b c`) == "abc"
  13. # #20067
  14. template defaultVal*(value : typed) {.pragma.}
  15. type A = ref object
  16. b {.defaultVal: "foo".}: string
  17. `$c` {.defaultVal: "bar".}: string
  18. let a = A(b: "a", `$c`: "b")
  19. echo "b.defaultVal = " & a.b.getCustomPragmaVal(defaultVal)
  20. echo "$c.defaultVal = " & a.`$c`.getCustomPragmaVal(defaultVal)