summary refs log tree commit diff stats
path: root/tests/notnil
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-01-13 02:10:03 +0100
committerAraq <rumpf_a@web.de>2014-01-13 02:10:03 +0100
commit20b5f31c03fb556ec0aa2428a40adbac004d8987 (patch)
tree58086941e7d6bb8f480ca1173a95722ada9435b2 /tests/notnil
parent51ee524109cf7e3e86c676bc1676063a01bfd979 (diff)
downloadNim-20b5f31c03fb556ec0aa2428a40adbac004d8987.tar.gz
new tester; all tests categorized
Diffstat (limited to 'tests/notnil')
-rw-r--r--tests/notnil/tnotnil.nim23
-rw-r--r--tests/notnil/tnotnil1.nim40
-rw-r--r--tests/notnil/tnotnil2.nim24
3 files changed, 87 insertions, 0 deletions
diff --git a/tests/notnil/tnotnil.nim b/tests/notnil/tnotnil.nim
new file mode 100644
index 000000000..fba7fa917
--- /dev/null
+++ b/tests/notnil/tnotnil.nim
@@ -0,0 +1,23 @@
+discard """
+  line: 22
+  errormsg: "type mismatch"
+"""
+
+type
+  PObj = ref TObj not nil
+  TObj = object
+    x: int
+  
+  MyString = string not nil
+
+#var x: PObj = nil
+
+proc p(x: string not nil): int =
+  result = 45
+
+proc q(x: MyString) = nil
+proc q2(x: string) = nil
+
+q2(nil)
+q(nil)
+
diff --git a/tests/notnil/tnotnil1.nim b/tests/notnil/tnotnil1.nim
new file mode 100644
index 000000000..863fe45f8
--- /dev/null
+++ b/tests/notnil/tnotnil1.nim
@@ -0,0 +1,40 @@
+discard """
+  errormsg: "'y' is provably nil"
+  line:38
+"""
+
+import strutils
+
+
+type
+  TObj = object
+    x, y: int
+
+type
+  superstring = string not nil
+
+
+proc q(s: superstring) =
+  echo s
+
+proc p2() =
+  var  a: string = "I am not nil" 
+  q(a) # but this should and does not
+
+p2()
+
+proc q(x: pointer not nil) =
+  nil
+
+proc p() =
+  var x: pointer
+  if not x.isNil:
+    q(x)
+  
+  let y = x
+  if not y.isNil:
+    q(y)
+  else:
+    q(y)
+
+p()
diff --git a/tests/notnil/tnotnil2.nim b/tests/notnil/tnotnil2.nim
new file mode 100644
index 000000000..bd6b8b675
--- /dev/null
+++ b/tests/notnil/tnotnil2.nim
@@ -0,0 +1,24 @@
+discard """
+  errormsg: "cannot prove 'y' is not nil"
+  line:20
+"""
+
+import strutils
+
+
+type
+  TObj = object
+    x, y: int
+
+proc q(x: pointer not nil) =
+  nil
+
+proc p() =
+  var x: pointer
+  let y = x
+  if not y.isNil or y != x:
+    q(y)
+  else:
+    q(y)
+
+p()