Skip to content

Commit f0b21b4

Browse files
demotomohiroAraq
andauthored
fixes #1155 (#1156)
`res.crossedProc` is always false when `res.kind` is neither `VarY` nor `LetY` so that nest procs using only global variables doesn't cause the error. --------- Co-authored-by: Andreas Rumpf <[email protected]>
1 parent 4fd6386 commit f0b21b4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/nimony/typenav.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ proc getLocalInfo*(c: var TypeCache; s: SymId): LocalInfo =
9898
if it.kind == compareTo:
9999
crossedProc = true
100100
if res.kind != NoSym:
101-
res.crossedProc = crossedProc
101+
res.crossedProc = crossedProc and res.kind in {VarY, LetY, ParamY, ResultY}
102102
return res
103103
it = it.parent
104104
compareTo = ProcScope
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/nimony/errmsgs/tclosureunavail.nim(17, 13) Error: cannot access local variable `x` from another routine; closures are not supported
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Tests if Nimony detects code that requires closures.
2+
# Remove this test when closures are supported.
3+
4+
# should not report closure error in following code
5+
var x = 0
6+
proc foo =
7+
discard x
8+
9+
proc bar =
10+
proc nested =
11+
discard x
12+
13+
# should report the error in following code.
14+
proc baz =
15+
var x = 1
16+
proc nested =
17+
discard x

0 commit comments

Comments
 (0)