Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/semgnrc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym,
result.typ = nil
onUse(n.info, s)
of skParam:
result = n
if s.owner == c.p.owner or true:
# Parameters of the routine currently being semchecked stay as local
# identifiers
result = n
else:
Comment thread
ringabout marked this conversation as resolved.
Outdated
# Preserve captured outer parameters so nested generic procs can still
# see them after the generic pre-pass.
result = newSymNode(s, n.info)
onUse(n.info, s)
of skType:
if (s.typ != nil) and
Expand Down
16 changes: 16 additions & 0 deletions tests/generics/t20811.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
discard """
output: '''42
42'''
"""

proc outer(j: int) =
proc genericInner[T](): int =
j

proc plainInner(): int =
j

echo genericInner[int]()
echo plainInner()

outer(42)
13 changes: 13 additions & 0 deletions tests/template/topensym.nim
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ block: # issue #22605 for templates, original complex example

doAssert g2(int) == "error"

block: # issue #20811
template injectError(body: untyped): untyped =
template error: untyped {.used, inject.} = "injected"
body

proc outerOpen(error: string): string =
injectError:
proc genericInner[T](): string =
error
genericInner[int]()

doAssert outerOpen("captured") == "injected"

block: # issue #23865 for templates
type Xxx = enum
error
Expand Down
Loading