From 9e3a82287731a13d49918586839e30b26d4863a8 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 10 Aug 2022 11:11:45 +0200 Subject: [PATCH] Fix: disregard early symbol lookup for error variable --- questionable/withoutresult.nim | 22 +++++++++++++++++++++- testmodules/result/test.nim | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/questionable/withoutresult.nim b/questionable/withoutresult.nim index a34ccff..cabba18 100644 --- a/questionable/withoutresult.nim +++ b/questionable/withoutresult.nim @@ -2,12 +2,32 @@ import std/macros import ./without import ./private/binderror -macro without*(condition, errorname, body): untyped = +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 + + for i in 0..