mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 06:18:51 +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.
26 lines
564 B
Nim
26 lines
564 B
Nim
discard """
|
|
cmd: "nim check --hints:off $file"
|
|
"""
|
|
|
|
block:
|
|
template foo =
|
|
when false:
|
|
let x = 123
|
|
else:
|
|
template x: untyped {.inject.} = 456
|
|
echo x #[tt.Error
|
|
^ undeclared identifier: 'x`gensym0'; if declared in a template, this identifier may be inconsistently marked inject or gensym]#
|
|
foo()
|
|
|
|
block:
|
|
template foo(y: static bool) =
|
|
block:
|
|
when y:
|
|
let x {.gensym.} = 123
|
|
else:
|
|
let x {.inject.} = 456
|
|
echo x #[tt.Error
|
|
^ undeclared identifier: 'x']#
|
|
foo(false)
|
|
foo(true)
|