summary refs log tree commit diff stats
path: root/lib/std/wrapnils.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-02-04 15:39:19 -0800
committerGitHub <noreply@github.com>2021-02-04 15:39:19 -0800
commitae9ba260f62b4ae3f7ab78be9eef544ff7dd72f2 (patch)
treef084ae4f13194dbc715f940e5ac8bc5777e88666 /lib/std/wrapnils.nim
parent2a60974ede6ce9176cfb3b4c74a6ae2ff84ba6f5 (diff)
downloadNim-ae9ba260f62b4ae3f7ab78be9eef544ff7dd72f2.tar.gz
clarify docs for wrapnils (#16929)
Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>
Diffstat (limited to 'lib/std/wrapnils.nim')
-rw-r--r--lib/std/wrapnils.nim9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/std/wrapnils.nim b/lib/std/wrapnils.nim
index 71205c887..5b2dd9769 100644
--- a/lib/std/wrapnils.nim
+++ b/lib/std/wrapnils.nim
@@ -19,8 +19,13 @@ runnableExamples:
   assert ?.f2.x1 == "a" # same as f2.x1 (no nil LHS in this chain)
   assert ?.Foo(x1: "a").x1 == "a" # can use constructor inside
 
-  # when you know a sub-expression is not nil, you can scope it as follows:
-  assert ?.(f2.x2.x2).x3[] == 0 # because `f` is nil
+  # when you know a sub-expression doesn't involve a `nil` (e.g. `f2.x2.x2`),
+  # you can scope it as follows:
+  assert ?.(f2.x2.x2).x3[] == 0
+
+  assert (?.f2.x2.x2).x3 == nil  # this terminates ?. early
+  import segfaults # enable `NilAccessDefect` exceptions
+  doAssertRaises(NilAccessDefect): echo (?.f2.x2.x2).x3[]
 
 type Wrapnil[T] = object
   valueImpl: T