diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-04-11 15:14:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-11 09:14:56 +0200 |
commit | 779bc8474b0e4d5d77d2619bd50eaa0fc111d1e6 (patch) | |
tree | d52d43d6a688b3cb93f2838c154e9096752489b8 /tests/stdlib | |
parent | 2bd2f2885873f5eb2c722b3647fd11ee480a2452 (diff) | |
download | Nim-779bc8474b0e4d5d77d2619bd50eaa0fc111d1e6.tar.gz |
fixes #4299 #12492 #10849; lambda lifting for JS backend (#23484)
fixes #4299 fixes #12492 fixes #10849 It binds `function` with `env`: `function.bind(:env)` to ease codegen for now
Diffstat (limited to 'tests/stdlib')
-rw-r--r-- | tests/stdlib/tclosures.nim | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/stdlib/tclosures.nim b/tests/stdlib/tclosures.nim new file mode 100644 index 000000000..84b033fa8 --- /dev/null +++ b/tests/stdlib/tclosures.nim @@ -0,0 +1,47 @@ +discard """ + targets: "c js" +""" + +import std/assertions + +block: # bug #4299 + proc scopeProc() = + proc normalProc() = + discard + + proc genericProc[T]() = + normalProc() + + genericProc[string]() + + scopeProc() + +block: # bug #12492 + proc foo() = + var i = 0 + proc bar() = + inc i + + bar() + doAssert i == 1 + + foo() + static: + foo() + +block: # bug #10849 + type + Generic[T] = ref object + getState: proc(): T + + proc newGeneric[T](): Generic[T] = + var state: T + + proc getState[T](): T = + state + + Generic[T](getState: getState) + + let g = newGeneric[int]() + let state = g.getState() + doAssert state == 0 |