diff --git a/questionable/withoutresult.nim b/questionable/withoutresult.nim index 17cd333..786cc49 100644 --- a/questionable/withoutresult.nim +++ b/questionable/withoutresult.nim @@ -2,13 +2,14 @@ import std/macros import ./without import ./private/binderror +const symbolKinds = {nnkSym, nnkOpenSymChoice, nnkClosedSymChoice} +const identKinds = {nnkIdent} + symbolKinds + proc undoSymbolResolution(expression, ident: NimNode): NimNode = ## Finds symbols in the expression that match the `ident` and replaces them ## with `ident`, effectively undoing any symbol resolution that happened ## before. - const symbolKinds = {nnkSym, nnkOpenSymChoice, nnkClosedSymChoice} - if expression.kind in symbolKinds and eqIdent($expression, $ident): return ident @@ -22,6 +23,9 @@ macro without*(condition, errorname, body: untyped): untyped = ## Used to place guards that ensure that a Result contains a value. ## Exposes error when Result does not contain a value. + if errorname.kind notin identKinds: + error("expected an identifier, got " & errorname.repr, errorname) + let errorIdent = ident $errorname # Nim's early symbol resolution might have picked up a symbol with the