diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 69bc9092bfe4..a21f95923114 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 000000000000..ff9402d952f7 --- /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()