From 1ff69eae17388be06221369b2bb08f8808905472 Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 31 Jan 2025 10:44:02 +0300 Subject: [PATCH] don't mark captured field sym in template as fully used (#24660) fixes #24657 (cherry picked from commit 647c6687f181ec6c68cb18ce958e3784b58a23a7) --- compiler/semtempl.nim | 7 ++++++- tests/template/tfielduse.nim | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/template/tfielduse.nim diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 69bc9092bfe40..a21f959231148 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -66,7 +66,12 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule; # for instance 'nextTry' is both in tables.nim and astalgo.nim ... if not isField or sfGenSym notin s.flags: result = newSymNode(s, info) - markUsed(c, info, s) + if isField: + # possibly not final field sym + incl(s.flags, sfUsed) + markOwnerModuleAsUsed(c, s) + else: + markUsed(c, info, s) onUse(info, s) else: result = n diff --git a/tests/template/tfielduse.nim b/tests/template/tfielduse.nim new file mode 100644 index 0000000000000..ff9402d952f7a --- /dev/null +++ b/tests/template/tfielduse.nim @@ -0,0 +1,9 @@ +# issue #24657 + +proc g() {.error.} = discard + +type T = object + g: int + +template B(): untyped = typeof(T.g) +type _ = B()