topensymoverride.nim 782 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. matrix: "--skipParentCfg --filenames:legacyRelProj"
  3. """
  4. const value = "captured"
  5. template fooOld(x: int, body: untyped): untyped =
  6. let value {.inject.} = "injected"
  7. body
  8. template foo(x: int, body: untyped): untyped =
  9. let value {.inject.} = "injected"
  10. {.push experimental: "genericsOpenSym".}
  11. body
  12. {.pop.}
  13. proc old[T](): string =
  14. fooOld(123):
  15. return value
  16. doAssert old[int]() == "captured"
  17. template oldTempl(): string =
  18. block:
  19. var res: string
  20. fooOld(123):
  21. res = value
  22. res
  23. doAssert oldTempl() == "captured"
  24. proc bar[T](): string =
  25. foo(123):
  26. return value
  27. doAssert bar[int]() == "injected"
  28. template barTempl(): string =
  29. block:
  30. var res: string
  31. foo(123):
  32. res = value
  33. res
  34. doAssert barTempl() == "injected"