summary refs log tree commit diff stats
path: root/tests/notnil/tnotnil3.nim
blob: 31a4efef783553d84634b738d7acf70e7e6e4b3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()