Skip to content

Commit

Permalink
fix nim-lang#22548;environment misses for type reference in iterator …
Browse files Browse the repository at this point in the history
…access nested in closure
  • Loading branch information
bung87 committed Aug 25, 2023
1 parent d677ed3 commit 256a490
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/lambdalifting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) =
detectCapturedVars(n[namePos], owner, c)
of nkReturnStmt:
detectCapturedVars(n[0], owner, c)
of nkIdentDefs:
detectCapturedVars(n[^1], owner, c)
else:
for i in 0..<n.len:
detectCapturedVars(n[i], owner, c)
Expand Down
17 changes: 17 additions & 0 deletions tests/iter/t22548.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type Xxx[T] = object

iterator x(v: string): char =
var v2: Xxx[int]

var y: v2.T

echo y

proc bbb(vv: string): proc () =
proc xxx() =
for c in x(vv):
echo c

return xxx

bbb("test")()

0 comments on commit 256a490

Please sign in to comment.