diff options
author | metagn <metagngn@gmail.com> | 2024-09-06 12:16:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-06 11:16:43 +0200 |
commit | bf865fa75aba5ed61f123e528044285a87bdd0b1 (patch) | |
tree | 66b72d7a35e0fe8125e3e89a7e9baf5f2884f5e8 | |
parent | d91297a330a4cccc4d82c06d4c33b16544b0c1bb (diff) | |
download | Nim-bf865fa75aba5ed61f123e528044285a87bdd0b1.tar.gz |
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`.
-rw-r--r-- | compiler/semgnrc.nim | 3 | ||||
-rw-r--r-- | tests/generics/tnestedtemplate.nim | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index e3a8daf99..16bb7f094 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 000000000..22d0a2d3c --- /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..<input.len: + s.add currPix + let pix = [1, 2, 3] + filterScanline(pix) + doAssert s == @[1, 2, 3] |