Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for Nim gensym bug #60

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading