tgenericcompiletimeproc.nim 706 B

123456789101112131415161718192021222324252627282930
  1. block: # issue #10753
  2. proc foo(x: int): int {.compileTime.} = x
  3. const a = foo(123)
  4. doAssert foo(123) == a
  5. proc bar[T](x: T): T {.compileTime.} = x
  6. const b = bar(123)
  7. doAssert bar(123) == b
  8. const c = bar("abc")
  9. doAssert bar("abc") == c
  10. block: # issue #22021
  11. proc foo(x: static int): int {.compileTime.} = x + 1
  12. doAssert foo(123) == 124
  13. block: # issue #19365
  14. proc f[T](x: static T): T {.compileTime.} = x + x
  15. doAssert f(123) == 246
  16. doAssert f(1.0) == 2.0
  17. block:
  18. # don't fold compile time procs in typeof
  19. proc fail[T](x: T): T {.compileTime.} =
  20. doAssert false
  21. x
  22. doAssert typeof(fail(123)) is typeof(123)
  23. proc p(x: int): int = x
  24. type Foo = typeof(p(fail(123)))