From b098ae696a73fdaac53b9e24a1f06173fdc7108c Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Sat, 20 Apr 2024 08:03:54 +0200 Subject: [PATCH] Workaround for Nim gensym bug Occasionally different `evaluated` symbols would be gensymmed to the same symbol. --- questionable/private/binderror.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/questionable/private/binderror.nim b/questionable/private/binderror.nim index d6973f5..92d40a9 100644 --- a/questionable/private/binderror.nim +++ b/questionable/private/binderror.nim @@ -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`")