mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
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.
(cherry picked from commit cd946084ab)
21 lines
403 B
Nim
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()
|