Files
Nim/tests/template/tinnerouterproc.nim
metagn cd946084ab make routine implicitly gensym when other gensym symbol exists again (#23842)
fixes #23813, partially reverts #23392

Before #23392, if a `gensym` symbol was defined before a proc with the
same name in a template even with an `inject` annotation, the proc would
be `gensym`. After #23392 the proc was instead changed to be `inject` as
long as no `gensym` annotation was given. Now, to keep compatibility
with the old behavior, the behavior is changed back to infer the proc as
`gensym` when no `inject` annotation is given, however an explicit
`inject` annotation will still inject the proc. This is also documented
in the manual as the old behavior was undocumented and the new behavior
is slightly different.
2024-07-16 08:47:06 +02:00

21 lines
403 B
Nim

block: # #20002
proc bar(x: int): int = 10
template foo =
proc bar(x: int): int {.gensym.} = x + 2
doAssert bar(3) == 5
discard 3.bar # evaluates to 10 but only check if it compiles for now
block:
foo()
block: # issue #23813
template r(body: untyped) =
proc x() {.gensym.} =
body
template g() =
r:
let y = 0
r:
proc y() = discard
y()
g()