Skip to content

Commit

Permalink
Workaround for Nim gensym bug
Browse files Browse the repository at this point in the history
Occasionally different `evaluated` symbols would be
gensymmed to the same symbol.
  • Loading branch information
markspanbroek committed Apr 20, 2024
1 parent 83ae4a6 commit b098ae6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions questionable/private/binderror.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ macro captureBindError*(error: var ref CatchableError, expression): auto =

# name of the error variable as a string literal
let errorVariableName = newLit($error)

let evaluated = genSym(nskLet, "evaluated")
quote do:
# add error variable to the top of the stack
static: errorVariableNames.add(`errorVariableName`)
# evaluate the expression
let evaluated = `expression`
let `evaluated` = `expression`
# pop error variable from the stack
static: discard errorVariableNames.pop()
# return the evaluated result
evaluated
`evaluated`

func unsafeError[T](_: Option[T]): ref CatchableError =
newException(ValueError, "Option is set to `none`")
Expand Down

0 comments on commit b098ae6

Please sign in to comment.