summary refs log tree commit diff stats
path: root/tests/notnil/tnotnil3.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/notnil/tnotnil3.nim')
-rw-r--r--tests/notnil/tnotnil3.nim35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/notnil/tnotnil3.nim b/tests/notnil/tnotnil3.nim
new file mode 100644
index 000000000..31a4efef7
--- /dev/null
+++ b/tests/notnil/tnotnil3.nim
@@ -0,0 +1,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()
+
ve a backup of csources-built nim to bin/nim_csources to avoid recompiling from csources (#8582)' href='/ahoang/Nim/commit/build_all.sh?h=devel&id=730ce53b71a207edf93abe09c14c150b9c360028'>730ce53b7 ^
1e89e5bf9 ^
506418ef5 ^
0bb76dde5 ^
e0afacb9f ^
0bb76dde5 ^
506418ef5 ^

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