tnil.nim 458 B

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