We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2a60974 commit ae9ba26Copy full SHA for ae9ba26
lib/std/wrapnils.nim
@@ -19,8 +19,13 @@ runnableExamples:
19
assert ?.f2.x1 == "a" # same as f2.x1 (no nil LHS in this chain)
20
assert ?.Foo(x1: "a").x1 == "a" # can use constructor inside
21
22
- # when you know a sub-expression is not nil, you can scope it as follows:
23
- 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:
24
+ assert ?.(f2.x2.x2).x3[] == 0
25
+
26
+ assert (?.f2.x2.x2).x3 == nil # this terminates ?. early
27
+ import segfaults # enable `NilAccessDefect` exceptions
28
+ doAssertRaises(NilAccessDefect): echo (?.f2.x2.x2).x3[]
29
30
type Wrapnil[T] = object
31
valueImpl: T
0 commit comments