summary refs log tree commit diff stats
path: root/lib/pure/options.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/options.nim')
-rw-r--r--lib/pure/options.nim15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/pure/options.nim b/lib/pure/options.nim
index 28c4e4984..dc5cfa4bf 100644
--- a/lib/pure/options.nim
+++ b/lib/pure/options.nim
@@ -58,8 +58,12 @@
 
 import typetraits
 
-type
-  SomePointer = ref | ptr | pointer
+when (NimMajor, NimMinor) >= (1, 1):
+  type
+    SomePointer = ref | ptr | pointer | proc
+else:
+  type
+    SomePointer = ref | ptr | pointer
 
 type
   Option*[T] = object
@@ -74,7 +78,7 @@ type
 
 
 proc option*[T](val: T): Option[T] =
-  ## Can be used to convert a pointer type (`ptr` or `ref`) to an option type.
+  ## Can be used to convert a pointer type (`ptr` or `ref` or `proc`) to an option type.
   ## It converts `nil` to `None`.
   ##
   ## See also:
@@ -482,6 +486,11 @@ when isMainModule:
 
       let tmp = option(intref)
       check(sizeof(tmp) == sizeof(ptr int))
+      
+      var prc = proc (x: int): int = x + 1
+      check(option(prc).isSome)
+      prc = nil
+      check(option(prc).isNone)
 
     test "none[T]":
       check(none[int]().isNone)