tescape_var_into_quotedo_as_const.nim 540 B

12345678910111213141516171819202122232425262728293031323334353637
  1. discard """
  2. output: '''ok'''
  3. """
  4. # bug #9864
  5. import macros, tables
  6. proc bar(shOpt: Table[string, int]) = discard
  7. macro dispatchGen(): untyped =
  8. var shOpt = initTable[string, int]()
  9. shOpt["foo"] = 10
  10. result = quote do:
  11. bar(`shOpt`)
  12. dispatchGen()
  13. type
  14. Foo = object
  15. data: seq[int]
  16. proc barB(a: Foo) = discard
  17. proc shOptB(): auto =
  18. var shOpt: Foo
  19. shOpt.data.setLen 1 # fails
  20. shOpt
  21. macro dispatchGenB(): untyped =
  22. var shOpt = shOptB() # fails
  23. result = quote do:
  24. barB(`shOpt`)
  25. dispatchGenB()
  26. echo "ok"