tgensymhijack.nim 682 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # issue #23326
  2. type Result*[E] = object
  3. e*: E
  4. proc error*[E](v: Result[E]): E = discard
  5. template valueOr*[E](self: Result[E], def: untyped): int =
  6. when E isnot void:
  7. when false:
  8. # Comment line below to make it work
  9. template error(): E {.used, gensym.} = s.e
  10. discard
  11. else:
  12. template error(): E {.used, inject.} =
  13. self.e
  14. def
  15. else:
  16. def
  17. block:
  18. let rErr = Result[string](e: "a")
  19. let rErrV = rErr.valueOr:
  20. ord(error[0])
  21. block:
  22. template foo(x: static bool): untyped =
  23. when x:
  24. let a = 123
  25. else:
  26. template a: untyped {.gensym.} = 456
  27. a
  28. doAssert foo(false) == 456
  29. doAssert foo(true) == 123