tnotnil3.nim 569 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. errormsg: "cannot prove 'variable' is not nil"
  3. line: 31
  4. """
  5. # bug #584
  6. # Testprogram for 'not nil' check
  7. {.experimental: "notnil".}
  8. const testWithResult = true
  9. type
  10. A = object
  11. B = object
  12. C = object
  13. a: ref A
  14. b: ref B
  15. proc testNotNil(c: ref C not nil) =
  16. discard
  17. when testWithResult:
  18. proc testNotNilOnResult(): ref C =
  19. new(result)
  20. #result.testNotNil() # Here 'not nil' can't be proved
  21. var variable: ref C
  22. new(variable)
  23. variable.testNotNil() # Here 'not nil' is proved
  24. when testWithResult:
  25. discard testNotNilOnResult()