tparams_gensymed.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # bug #1915
  2. import macros
  3. # Test that parameters are properly gensym'ed finally:
  4. template genNodeKind(kind, name: untyped) =
  5. proc name*(children: varargs[NimNode]): NimNode {.compiletime.}=
  6. result = newNimNode(kind)
  7. for c in children:
  8. result.add(c)
  9. genNodeKind(nnkNone, None)
  10. # Test that generics in templates still work (regression to fix #1915)
  11. # bug #2004
  12. type Something = object
  13. proc testA(x: Something) = discard
  14. template def(name: untyped) =
  15. proc testB[T](reallyUniqueName: T) =
  16. `test name`(reallyUniqueName)
  17. def A
  18. var x: Something
  19. testB(x)
  20. # bug #2215
  21. # Test that templates in generics still work (regression to fix the
  22. # regression...)
  23. template forStatic(index, slice, predicate: untyped) =
  24. const a = slice.a
  25. const b = slice.b
  26. when a <= b:
  27. template iteration(i: int) =
  28. block:
  29. const index = i
  30. predicate
  31. template iterateStartingFrom(i: int) =
  32. when i <= b:
  33. iteration i
  34. iterateStartingFrom i + 1
  35. iterateStartingFrom a
  36. proc concreteProc(x: int) =
  37. forStatic i, 0..3:
  38. echo i
  39. proc genericProc(x: any) =
  40. forStatic i, 0..3:
  41. echo i
  42. concreteProc(7) # This works
  43. genericProc(7) # This doesn't compile