Files
Nim/tests/errmsgs/tinconsistentgensym.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

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)