Skip to content

Commit b28c316

Browse files
committed
Add test case
1 parent 0b96aa7 commit b28c316

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

tests/closure/tcapture.nim

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
discard """
22
output: '''
3-
to be, or not to be'''
3+
to be, or not to be
4+
(v: 1)
5+
(v: 1)
6+
'''
47
joinable: false
58
"""
69

@@ -9,4 +12,15 @@ import sequtils, sugar
912
let m = @[proc (s: string): string = "to " & s, proc (s: string): string = "not to " & s]
1013
var l = m.mapIt(capture([it], proc (s: string): string = it(s)))
1114
let r = l.mapIt(it("be"))
12-
echo r[0] & ", or " & r[1]
15+
echo r[0] & ", or " & r[1]
16+
17+
type O = object
18+
v: int
19+
var o = O(v: 1)
20+
var execute: proc()
21+
capture [o]:
22+
execute = proc() =
23+
echo o
24+
execute()
25+
o.v = -1
26+
execute()

0 commit comments

Comments
 (0)