tquotedo.nim 654 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. discard """
  2. output: '''
  3. 123
  4. Hallo Welt
  5. Hallo Welt
  6. 1
  7. ()
  8. '''
  9. """
  10. import macros
  11. macro mac(): untyped =
  12. quote do:
  13. proc test(): int =
  14. (proc(): int = result = 123)()
  15. mac()
  16. echo test()
  17. macro foobar(arg: untyped): untyped =
  18. result = arg
  19. result.add quote do:
  20. `result`
  21. foobar:
  22. echo "Hallo Welt"
  23. # bug #3744
  24. import macros
  25. macro t(): untyped =
  26. return quote do:
  27. proc tp(): int =
  28. result = 1
  29. t()
  30. echo tp()
  31. # https://github.com/nim-lang/Nim/issues/9866
  32. type
  33. # Foo = int # works
  34. Foo = object # fails
  35. macro dispatchGen(): untyped =
  36. var shOpt: Foo
  37. result = quote do:
  38. let baz = `shOpt`
  39. echo `shOpt`
  40. dispatchGen()