From 8daae270891e692c0e826f856b1a38df91e72171 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 7 Jun 2023 16:23:55 +0200 Subject: [PATCH] Do not edit AST nodes, make a copy first Fixes error "typechecked nodes may not be modified" --- questionable/chaining.nim | 4 ++++ questionable/withoutresult.nim | 1 + 2 files changed, 5 insertions(+) diff --git a/questionable/chaining.nim b/questionable/chaining.nim index e2c97cc..65ecaa2 100644 --- a/questionable/chaining.nim +++ b/questionable/chaining.nim @@ -22,23 +22,27 @@ template chain(option: typed, identifier: untyped{nkIdent}): untyped = macro chain(option: typed, infix: untyped{nkInfix}): untyped = # chain is of shape: option.?left `operator` right + let infix = infix.copyNimTree() let left = infix[1] infix[1] = quote do: `option`.?`left` infix macro chain(option: typed, bracket: untyped{nkBracketExpr}): untyped = # chain is of shape: option.?left[right] + let bracket = bracket.copyNimTree() let left = bracket[0] bracket[0] = quote do: `option`.?`left` bracket macro chain(option: typed, dot: untyped{nkDotExpr}): untyped = # chain is of shape: option.?left.right + let dot = dot.copyNimTree() let left = dot[0] dot[0] = quote do: `option`.?`left` dot macro chain(option: typed, call: untyped{nkCall}): untyped = + let call = call.copyNimTree() let procedure = call[0] if call.len == 1: # chain is of shape: option.?procedure() diff --git a/questionable/withoutresult.nim b/questionable/withoutresult.nim index cabba18..17cd333 100644 --- a/questionable/withoutresult.nim +++ b/questionable/withoutresult.nim @@ -12,6 +12,7 @@ proc undoSymbolResolution(expression, ident: NimNode): NimNode = if expression.kind in symbolKinds and eqIdent($expression, $ident): return ident + let expression = expression.copyNimTree() for i in 0..