std/wrapnils does not use experimental:dotOperators anymore (#16996)

This commit is contained in:
Timothee Cour 2021-02-10 09:50:50 -08:00 • committed by GitHub
commit f3e4c4d6e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View file

@ -140,6 +140,10 @@ with other backends. see #9125. Use `-d:nimLegacyJsRound` for previous behavior.
- Added experimental `linenoise.readLineStatus` to get line and status (e.g. ctrl-D or ctrl-C). - Added experimental `linenoise.readLineStatus` to get line and status (e.g. ctrl-D or ctrl-C).
- `std/wrapnils` doesn't use `experimental:dotOperators` anymore, avoiding
issues like https://github.com/nim-lang/Nim/issues/13063 (which affected error messages)
for modules importing `std/wrapnils`.
## Language changes ## Language changes
- `nimscript` now handles `except Exception as e`. - `nimscript` now handles `except Exception as e`.

View file

@ -2,8 +2,7 @@
## This simplifies code by reducing need for if-else branches around intermediate values ## This simplifies code by reducing need for if-else branches around intermediate values
## that maybe be nil. ## that maybe be nil.
## ##
## Note: experimental module and relies on {.experimental: "dotOperators".} ## Note: experimental module, unstable API.
## Unstable API.
runnableExamples: runnableExamples:
type Foo = ref object type Foo = ref object
@ -39,9 +38,7 @@ template unwrap(a: Wrapnil): untyped =
## See top-level example. ## See top-level example.
a.valueImpl a.valueImpl
{.push experimental: "dotOperators".} template fakeDot*(a: Wrapnil, b): untyped =
template `.`*(a: Wrapnil, b): untyped =
## See top-level example. ## See top-level example.
let a1 = a # to avoid double evaluations let a1 = a # to avoid double evaluations
let a2 = a1.valueImpl let a2 = a1.valueImpl
@ -58,8 +55,6 @@ template `.`*(a: Wrapnil, b): untyped =
# nil is "sticky"; this is needed, see tests # nil is "sticky"; this is needed, see tests
default(T) default(T)
{.pop.}
proc isValid(a: Wrapnil): bool = proc isValid(a: Wrapnil): bool =
## Returns true if `a` didn't contain intermediate `nil` values (note that ## Returns true if `a` didn't contain intermediate `nil` values (note that
## `a.valueImpl` itself can be nil even in that case) ## `a.valueImpl` itself can be nil even in that case)
@ -90,16 +85,18 @@ template `[]`*(a: Wrapnil): untyped =
import std/macros import std/macros
proc replace(n: NimNode): NimNode = 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 doAssert n.len == 1
newCall(bindSym"wrapnil", n[0]) result = newCall(bindSym"wrapnil", n[0])
elif n.kind in {nnkCall, nnkObjConstr}: elif n.kind in {nnkCall, nnkObjConstr}:
newCall(bindSym"wrapnil", n) result = newCall(bindSym"wrapnil", n)
elif n.len == 0: elif n.len == 0:
newCall(bindSym"wrapnil", n) result = newCall(bindSym"wrapnil", n)
else: else:
n[0] = replace(n[0]) n[0] = replace(n[0])
n result = n
macro `?.`*(a: untyped): untyped = macro `?.`*(a: untyped): untyped =
## Transforms `a` into an expression that can be safely evaluated even in ## Transforms `a` into an expression that can be safely evaluated even in