Skip to content

Commit

Permalink
fix undeclared identifier in templates in generics (#24069)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
metagn committed Sep 6, 2024
1 parent d91297a commit bf865fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/semgnrc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions tests/generics/tnestedtemplate.nim
Original file line number Diff line number Diff line change
@@ -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..<input.len:
s.add currPix
let pix = [1, 2, 3]
filterScanline(pix)
doAssert s == @[1, 2, 3]

0 comments on commit bf865fa

Please sign in to comment.