diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-02-10 09:50:50 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-10 18:50:50 +0100 |
commit | f3e4c4d6e1f4822f598e738a4af23944775ea667 (patch) | |
tree | ebf82b9bb5f6c49e40078cbabb56eede2fb29bbb /lib/std | |
parent | 9bd4f503f4afcdcb8a42475c2f9c97a20830fae1 (diff) | |
download | Nim-f3e4c4d6e1f4822f598e738a4af23944775ea667.tar.gz |
std/wrapnils does not use experimental:dotOperators anymore (#16996)
Diffstat (limited to 'lib/std')
-rw-r--r-- | lib/std/wrapnils.nim | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/std/wrapnils.nim b/lib/std/wrapnils.nim index c9120e1b7..7c0672176 100644 --- a/lib/std/wrapnils.nim +++ b/lib/std/wrapnils.nim @@ -2,8 +2,7 @@ ## This simplifies code by reducing need for if-else branches around intermediate values ## that maybe be nil. ## -## Note: experimental module and relies on {.experimental: "dotOperators".} -## Unstable API. +## Note: experimental module, unstable API. runnableExamples: type Foo = ref object @@ -39,9 +38,7 @@ template unwrap(a: Wrapnil): untyped = ## See top-level example. a.valueImpl -{.push experimental: "dotOperators".} - -template `.`*(a: Wrapnil, b): untyped = +template fakeDot*(a: Wrapnil, b): untyped = ## See top-level example. let a1 = a # to avoid double evaluations let a2 = a1.valueImpl @@ -58,8 +55,6 @@ template `.`*(a: Wrapnil, b): untyped = # nil is "sticky"; this is needed, see tests default(T) -{.pop.} - proc isValid(a: Wrapnil): bool = ## Returns true if `a` didn't contain intermediate `nil` values (note that ## `a.valueImpl` itself can be nil even in that case) @@ -90,16 +85,18 @@ template `[]`*(a: Wrapnil): untyped = import std/macros proc replace(n: NimNode): NimNode = - if n.kind == nnkPar: + if n.kind == nnkDotExpr: + result = newCall(bindSym"fakeDot", replace(n[0]), n[1]) + elif n.kind == nnkPar: doAssert n.len == 1 - newCall(bindSym"wrapnil", n[0]) + result = newCall(bindSym"wrapnil", n[0]) elif n.kind in {nnkCall, nnkObjConstr}: - newCall(bindSym"wrapnil", n) + result = newCall(bindSym"wrapnil", n) elif n.len == 0: - newCall(bindSym"wrapnil", n) + result = newCall(bindSym"wrapnil", n) else: n[0] = replace(n[0]) - n + result = n macro `?.`*(a: untyped): untyped = ## Transforms `a` into an expression that can be safely evaluated even in |