From 1ce954a0cf7f74631ca0c9514aef6bc5bc74f3a7 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 16 Jul 2024 00:47:06 -0600 Subject: [PATCH] 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. (cherry picked from commit cd946084abdf3ab64b2540e2f29c1034ae1511e5) --- compiler/semtempl.nim | 12 +++++++----- doc/manual.md | 9 ++++++--- tests/errmsgs/tinconsistentgensym.nim | 2 +- tests/template/tinnerouterproc.nim | 12 ++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 871a10db98..0fc8f36366 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -255,25 +255,27 @@ proc semTemplSymbol(c: PContext, n: PNode, s: PSym; isField: bool): PNode = if not isField: styleCheckUse(c, n.info, s) -proc semRoutineInTemplName(c: var TemplCtx, n: PNode): PNode = +proc semRoutineInTemplName(c: var TemplCtx, n: PNode, explicitInject: bool): PNode = result = n if n.kind == nkIdent: let s = qualifiedLookUp(c.c, n, {}) if s != nil: - if s.owner == c.owner and s.kind == skParam: + if s.owner == c.owner and (s.kind == skParam or + (sfGenSym in s.flags and not explicitInject)): incl(s.flags, sfUsed) result = newSymNode(s, n.info) onUse(n.info, s) else: for i in 0..