tnil.nim 465 B

1234567891011121314151617181920212223
  1. {.experimental: "notnil".}
  2. type
  3. MyPointer = distinct pointer
  4. MyString = distinct string
  5. MyInt = distinct int
  6. proc foo(a: MyPointer): int =
  7. # workaround a Windows 'repr' difference:
  8. cast[int](a)
  9. doAssert foo(cast[MyPointer](1)) == 1
  10. doAssert foo(cast[MyPointer](nil)) == 0
  11. doAssert foo(MyPointer(nil)) == 0
  12. var p: MyPointer
  13. p = cast[MyPointer](1)
  14. p = cast[MyPointer](nil)
  15. p = nil.MyPointer
  16. var i: MyInt
  17. i = 1.MyInt
  18. doAssert(compiles(i = nil) == false)