diff options
author | Bung <crc32@qq.com> | 2023-08-09 15:43:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-09 09:43:39 +0200 |
commit | 989da75b84e15a6d585e8b03d2bcd0c42a90c2fb (patch) | |
tree | 348122cf414a84389dbbfa676927c1e1fdec642d /tests/iter/t20891.nim | |
parent | c622e58db968da29e743472d6619137598cc546a (diff) | |
download | Nim-989da75b84e15a6d585e8b03d2bcd0c42a90c2fb.tar.gz |
fix #20891 Illegal capture error of env its self (#22414)
* fix #20891 Illegal capture error of env its self * fix innerClosure too earlier, make condition shorter
Diffstat (limited to 'tests/iter/t20891.nim')
-rw-r--r-- | tests/iter/t20891.nim | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/iter/t20891.nim b/tests/iter/t20891.nim new file mode 100644 index 000000000..34deec41b --- /dev/null +++ b/tests/iter/t20891.nim @@ -0,0 +1,28 @@ +import macros, tables + +var mapping {.compileTime.}: Table[string, NimNode] + +macro register(a: static[string], b: typed): untyped = + mapping[a] = b + +macro getPtr(a: static[string]): untyped = + result = mapping[a] + +proc foo() = + iterator it() {.closure.} = + discard + proc getIterPtr(): pointer {.nimcall.} = + rawProc(it) + register("foo", getIterPtr()) + discard getIterPtr() # Comment either this to make it work +foo() # or this + +proc bar() = + iterator it() {.closure.} = + discard getPtr("foo") # Or this + discard + proc getIterPtr(): pointer {.nimcall.} = + rawProc(it) + register("bar", getIterPtr()) + discard getIterPtr() +bar() |