summary refs log blame commit diff stats
path: root/tests/notnil/tnotnil3.nim
blob: 31a4efef783553d84634b738d7acf70e7e6e4b3b (plain) (tree)
1
2
3
4
5
6
7
8






                                                
                          


























                                                         
discard """
  errormsg: "cannot prove 'variable' is not nil"
  line: 31
"""

# bug #584
# Testprogram for 'not nil' check
{.experimental: "notnil".}
const testWithResult = true

type
  A = object
  B = object
  C = object
    a: ref A
    b: ref B


proc testNotNil(c: ref C not nil) =
  discard


when testWithResult:
  proc testNotNilOnResult(): ref C =
    new(result)
    #result.testNotNil() # Here 'not nil' can't be proved


var variable: ref C
new(variable)
variable.testNotNil() # Here 'not nil' is proved

when testWithResult:
  discard testNotNilOnResult()