Fix redefinition of 'T`gensymXX' error

In rare instances, the Nim compiler will generate the same
symbol more than once. Adding a block works around this issue.

Reproducing this behavior in a unit test has proved elusive.
This commit is contained in:
Mark Spanbroek 2022-10-20 12:08:51 +02:00 committed by markspanbroek
parent 30e4184a99
commit f78bdd9d58

View File

@ -4,8 +4,9 @@ macro `.?`*(expression: typed, brackets: untyped{nkBracket}): untyped =
# chain is of shape: expression.?[index]
let index = brackets[0]
quote do:
type T = typeof(`expression`[`index`])
try:
`expression`[`index`].some
except KeyError:
T.none
block:
type T = typeof(`expression`[`index`])
try:
`expression`[`index`].some
except KeyError:
T.none