tgenericcompiletimeproc.nim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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)))
  25. block: # issue #24150, related regression
  26. proc w(T: type): T {.compileTime.} = default(ptr T)[]
  27. template y(v: auto): auto = typeof(v) is int
  28. discard compiles(y(w int))
  29. proc s(): int {.compileTime.} = discard
  30. discard s()
  31. block: # issue #24228, also related regression
  32. proc d(_: static[string]) = discard $0
  33. proc m(_: static[string]) = d("")
  34. iterator v(): int {.closure.} =
  35. template a(n: untyped) =
  36. when typeof(n) is void:
  37. n
  38. else:
  39. n
  40. a(m(""))
  41. let _ = v
  42. block: # issue #24228 simplified
  43. proc d[T]() =
  44. let x = $0
  45. proc v() =
  46. when typeof(d[string]()) is void:
  47. d[string]()
  48. v()