Workaround for Nim gensym bug
Occasionally different `evaluated` symbols would be gensymmed to the same symbol.
This commit is contained in:
parent
83ae4a6409
commit
b098ae696a
|
@ -11,15 +11,17 @@ macro captureBindError*(error: var ref CatchableError, expression): auto =
|
||||||
|
|
||||||
# name of the error variable as a string literal
|
# name of the error variable as a string literal
|
||||||
let errorVariableName = newLit($error)
|
let errorVariableName = newLit($error)
|
||||||
|
|
||||||
|
let evaluated = genSym(nskLet, "evaluated")
|
||||||
quote do:
|
quote do:
|
||||||
# add error variable to the top of the stack
|
# add error variable to the top of the stack
|
||||||
static: errorVariableNames.add(`errorVariableName`)
|
static: errorVariableNames.add(`errorVariableName`)
|
||||||
# evaluate the expression
|
# evaluate the expression
|
||||||
let evaluated = `expression`
|
let `evaluated` = `expression`
|
||||||
# pop error variable from the stack
|
# pop error variable from the stack
|
||||||
static: discard errorVariableNames.pop()
|
static: discard errorVariableNames.pop()
|
||||||
# return the evaluated result
|
# return the evaluated result
|
||||||
evaluated
|
`evaluated`
|
||||||
|
|
||||||
func unsafeError[T](_: Option[T]): ref CatchableError =
|
func unsafeError[T](_: Option[T]): ref CatchableError =
|
||||||
newException(ValueError, "Option is set to `none`")
|
newException(ValueError, "Option is set to `none`")
|
||||||
|
|
Loading…
Reference in New Issue