From cd946084abdf3ab64b2540e2f29c1034ae1511e5 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. --- 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 f2083c85c4..c6f2fb60cc 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -256,25 +256,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..