tstatic.nim 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. discard """
  2. targets: "c cpp js"
  3. """
  4. import std/strutils
  5. # bug #6133
  6. template main() =
  7. block:
  8. block:
  9. proc foo(q: string, a: int): int =
  10. result = q.len
  11. proc foo(q: static[string]): int =
  12. result = foo(q, 5)
  13. doAssert foo("123") == 3
  14. block:
  15. type E = enum A
  16. if false:
  17. var e = A
  18. discard $e
  19. proc foo(a: string): int =
  20. len(a) # 16640
  21. proc foo(a: static[bool]): int {.used.} =
  22. discard
  23. doAssert foo("") == 0
  24. block:
  25. proc foo(a: string): int =
  26. len(a)
  27. proc foo(a: static[bool]): int {.used.} =
  28. discard
  29. doAssert foo("abc") == 3
  30. block:
  31. proc parseInt(f: static[bool]): int {.used.} = discard
  32. doAssert "123".parseInt == 123
  33. block:
  34. type
  35. MyType = object
  36. field: float32
  37. AType[T: static MyType] = distinct range[0f32 .. T.field]
  38. var a: AType[MyType(field: 5f32)]
  39. proc n(S: static Slice[int]): range[S.a..S.b] = discard
  40. assert typeof(n 1..2) is range[1..2]
  41. static: main()
  42. main()