Create identifiers with `genSym`

This commit is contained in:
Nickolay Bukreyev 2023-11-13 21:10:34 +07:00 committed by markspanbroek
parent 440debc7c3
commit fe47a19825
2 changed files with 12 additions and 3 deletions

View File

@ -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:

View File

@ -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: