mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
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`.
(cherry picked from commit bf865fa75a)
This commit is contained in:
@@ -577,7 +577,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:
|
||||
|
||||
9
tests/generics/tnestedtemplate.nim
Normal file
9
tests/generics/tnestedtemplate.nim
Normal file
@@ -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]
|
||||
Reference in New Issue
Block a user