From fe47a198252677c2a648a7bc17623de0822e7d12 Mon Sep 17 00:00:00 2001 From: Nickolay Bukreyev Date: Mon, 13 Nov 2023 21:10:34 +0700 Subject: [PATCH] Create identifiers with `genSym` --- questionable/binding.nim | 6 +++--- testmodules/options/test.nim | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/questionable/binding.nim b/questionable/binding.nim index e688085..8d8c311 100644 --- a/questionable/binding.nim +++ b/questionable/binding.nim @@ -45,9 +45,9 @@ proc newUnpackTupleNode(names: NimNode, value: NimNode): NimNode = nnkLetSection.newTree(vartuple) macro bindTuple(names, expression): bool = - let opt = ident("option") - let evaluated = ident("evaluated") - let T = ident("T") + let opt = genSym(nskLet, "option") + let evaluated = genSym(nskLet, "evaluated") + let T = genSym(nskType, "T") let value = quote do: if `opt`.isSome: diff --git a/testmodules/options/test.nim b/testmodules/options/test.nim index 62d4e6f..98b7119 100644 --- a/testmodules/options/test.nim +++ b/testmodules/options/test.nim @@ -288,6 +288,15 @@ suite "optionals": else: fail() + test "=? for tuples does not leak symbols into caller's scope": + const evaluated = "" + type T = string + if (a,) =? some (0,): + check a == 0 + check option is proc + check evaluated is string + check T is string + test "without statement can be used for early returns": proc test1 = without a =? 42.some: