summary refs log tree commit diff stats
path: root/tests/reject
diff options
context:
space:
mode:
Diffstat (limited to 'tests/reject')
-rw-r--r--tests/reject/tdisallowif.nim2
-rw-r--r--tests/reject/tnotnil1.nim24
-rw-r--r--tests/reject/tnotnil2.nim24
-rw-r--r--tests/reject/tuninit1.nim36
4 files changed, 85 insertions, 1 deletions
diff --git a/tests/reject/tdisallowif.nim b/tests/reject/tdisallowif.nim
index f7bb7098b..10f54288a 100644
--- a/tests/reject/tdisallowif.nim
+++ b/tests/reject/tdisallowif.nim
@@ -21,7 +21,7 @@ s[0] = substr(s[0], 0, 2)
 
 echo s[0]
 
-if true:
+if s[0] != "hi":
   echo "do it"
   echo "more branches"
 else:
diff --git a/tests/reject/tnotnil1.nim b/tests/reject/tnotnil1.nim
new file mode 100644
index 000000000..3535bbd63
--- /dev/null
+++ b/tests/reject/tnotnil1.nim
@@ -0,0 +1,24 @@
+discard """
+  errormsg: "'y' is provably nil"
+  line:22
+"""
+
+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:
+    q(y)
+  else:
+    q(y)
+
+p()
diff --git a/tests/reject/tnotnil2.nim b/tests/reject/tnotnil2.nim
new file mode 100644
index 000000000..bd6b8b675
--- /dev/null
+++ b/tests/reject/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()
diff --git a/tests/reject/tuninit1.nim b/tests/reject/tuninit1.nim
new file mode 100644
index 000000000..2a994b187
--- /dev/null
+++ b/tests/reject/tuninit1.nim
@@ -0,0 +1,36 @@
+discard """
+  errormsg: "'y' might not have been initialized"
+  line:34
+"""
+
+import strutils
+
+{.warning[Uninit]:on.}
+
+proc p =
+  var x, y, z: int
+  if stdin.readLine == "true":
+    x = 34
+    
+    while false:
+      y = 999
+      break
+      
+    while true:
+      if x == 12: break
+      y = 9999
+      
+    try:
+      z = parseInt("1233")
+    except E_Base:
+      case x
+      of 34: z = 123
+      of 13: z = 34
+      else: z = 8
+  else:
+    y = 3444
+    x = 3111
+    z = 0
+  echo x, y, z
+  
+p()