summary refs log tree commit diff stats
path: root/tests/ccgbugs/t9286.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ccgbugs/t9286.nim')
-rw-r--r--tests/ccgbugs/t9286.nim22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/ccgbugs/t9286.nim b/tests/ccgbugs/t9286.nim
new file mode 100644
index 000000000..2fec23307
--- /dev/null
+++ b/tests/ccgbugs/t9286.nim
@@ -0,0 +1,22 @@
+discard """
+  action: run
+"""
+
+import options
+type Foo  = ref object
+  i:      int
+
+proc next(foo: Foo): Option[Foo] =
+  try:    doAssert(foo.i == 0)
+  except: return      # 2º: none
+  return some(foo)    # 1º: some
+
+proc test =
+  let foo = Foo()
+  var opt = next(foo) # 1º Some
+  while isSome(opt) and foo.i < 10:
+    inc(foo.i)
+    opt = next(foo)   # 2º None
+  doAssert foo.i == 1, $foo.i
+
+test()