Workaround for Nim gensym bug

Occasionally different `evaluated` symbols would be
gensymmed to the same symbol.
This commit is contained in:
Mark Spanbroek 2024-04-20 08:03:54 +02:00 committed by markspanbroek
parent 83ae4a6409
commit b098ae696a
1 changed files with 4 additions and 2 deletions

View File

@ -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`")