tredefinition_override.nim 812 B

12345678910111213141516171819202122232425262728293031323334
  1. {.push warningAsError[ImplicitTemplateRedefinition]: on.}
  2. doAssert not (compiles do:
  3. template foo(): int = 1
  4. template foo(): int = 2)
  5. doAssert (compiles do:
  6. template foo(): int = 1
  7. template foo(): int {.redefine.} = 2)
  8. doAssert not (compiles do:
  9. block:
  10. template foo() =
  11. template bar: string {.gensym.} = "a"
  12. template bar: string {.gensym.} = "b"
  13. foo())
  14. doAssert (compiles do:
  15. block:
  16. template foo() =
  17. template bar: string {.gensym.} = "a"
  18. template bar: string {.gensym, redefine.} = "b"
  19. foo())
  20. block:
  21. template foo(): int = 1
  22. template foo(): int {.redefine.} = 2
  23. doAssert foo() == 2
  24. block:
  25. template foo(): string =
  26. template bar: string {.gensym.} = "a"
  27. template bar: string {.gensym, redefine.} = "b"
  28. bar()
  29. doAssert foo() == "b"
  30. {.pop.}