diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2022-11-02 15:29:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 15:29:46 +0800 |
commit | 87f7f505534baaa2410acfb976181c25628410a7 (patch) | |
tree | ba6284907bef3304314813fbc155c1e57e9bfc4e /tests/effects | |
parent | 841d9d59755f805245d862456d53e4fd8a426813 (diff) | |
download | Nim-87f7f505534baaa2410acfb976181c25628410a7.tar.gz |
closes #14216; add testcase (#20733)
Diffstat (limited to 'tests/effects')
-rw-r--r-- | tests/effects/teffectsmisc.nim | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/effects/teffectsmisc.nim b/tests/effects/teffectsmisc.nim new file mode 100644 index 000000000..8fb95b275 --- /dev/null +++ b/tests/effects/teffectsmisc.nim @@ -0,0 +1,39 @@ +discard """ + output: ''' +printing from adder +''' +""" + +import std/sugar + +block: + proc makeAdder(a: int): (int) -> void = + proc discard_adder(x: int) {.closure.} = + discard a + x + + proc echo_adder(x: int) {.closure.} = + echo("printing from adder") + + if a > 0: + discard_adder + else: + echo_adder + + let newAdder = makeAdder(0) + newAdder(5) + +block: + proc makeAdder(a: int): (int) -> void = + proc discard_adder(x: int) {.closure.} = + discard a + x + + proc echo_adder(x: int) {.closure.} = + echo("printing from adder") + + if a > 0: + echo_adder + else: + discard_adder + + let newAdder = makeAdder(0) + newAdder(5) |