summary refs log tree commit diff stats
path: root/tests/accept/compile
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-01-05 23:47:12 +0100
committerAraq <rumpf_a@web.de>2011-01-05 23:47:12 +0100
commitce672c19d245827f8809dc1c914f42003cb56bdc (patch)
tree43a66e6de58c35b61bdbc3d2ea6d3af4cc4eacba /tests/accept/compile
parent5635fde06024b00bb874126bea208f07b4b8db9d (diff)
parentbab74b6dce13f69b7f3017b27a472ba4a260c4bb (diff)
downloadNim-ce672c19d245827f8809dc1c914f42003cb56bdc.tar.gz
Merge branch 'master' of github.com:Araq/Nimrod
Diffstat (limited to 'tests/accept/compile')
-rw-r--r--tests/accept/compile/tgenericvariant.nim23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/accept/compile/tgenericvariant.nim b/tests/accept/compile/tgenericvariant.nim
new file mode 100644
index 000000000..51d01355a
--- /dev/null
+++ b/tests/accept/compile/tgenericvariant.nim
@@ -0,0 +1,23 @@
+type  
+  TMaybe[T] = object
+    case empty: Bool
+    of False: value: T
+    else: nil
+
+proc Just*[T](val: T): TMaybe[T] =
+  result.empty = False
+  result.value = val
+
+proc Nothing[T](): TMaybe[T] =
+  result.empty = True
+
+proc safeReadLine(): TMaybe[string] =
+  var r = stdin.readLine()
+  if r == "": return Nothing[string]()
+  else: return Just(r)
+
+when isMainModule:
+  var Test = Just("Test")
+  echo(Test.value)
+  var mSomething = safeReadLine()
+  echo(mSomething.value)