From bf865fa75aba5ed61f123e528044285a87bdd0b1 Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 6 Sep 2024 12:16:43 +0300 Subject: [PATCH] fix undeclared identifier in templates in generics (#24069) fixes #13979 Fixes templates in generics that use identifiers that aren't defined yet, giving an early `undeclared identifier` error, by just marking template bodies as in a mixin context in `semgnrc`. --- compiler/semgnrc.nim | 3 ++- tests/generics/tnestedtemplate.nim | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/generics/tnestedtemplate.nim diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index e3a8daf994d5..16bb7f094652 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -613,7 +613,8 @@ proc semGenericStmt(c: PContext, n: PNode, else: body = getBody(c.graph, s) else: body = n[bodyPos] - n[bodyPos] = semGenericStmtScope(c, body, flags, ctx) + let bodyFlags = if n.kind == nkTemplateDef: flags + {withinMixin} else: flags + n[bodyPos] = semGenericStmtScope(c, body, bodyFlags, ctx) closeScope(c) of nkPragma, nkPragmaExpr: discard of nkExprColonExpr, nkExprEqExpr: diff --git a/tests/generics/tnestedtemplate.nim b/tests/generics/tnestedtemplate.nim new file mode 100644 index 000000000000..22d0a2d3ce9a --- /dev/null +++ b/tests/generics/tnestedtemplate.nim @@ -0,0 +1,9 @@ +block: # issue #13979 + var s: seq[int] + proc filterScanline[T](input: openArray[T]) = + template currPix: untyped = input[i] + for i in 0..