From b28c316d10a585ca1ee19c257e7eb8d6c9308c2e Mon Sep 17 00:00:00 2001 From: Clyybber Date: Sun, 2 Feb 2020 02:16:13 +0100 Subject: [PATCH] Add test case --- tests/closure/tcapture.nim | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/closure/tcapture.nim b/tests/closure/tcapture.nim index 304a76285fb6..ff3490f07eb1 100644 --- a/tests/closure/tcapture.nim +++ b/tests/closure/tcapture.nim @@ -1,6 +1,9 @@ discard """ output: ''' -to be, or not to be''' +to be, or not to be +(v: 1) +(v: 1) +''' joinable: false """ @@ -9,4 +12,15 @@ import sequtils, sugar let m = @[proc (s: string): string = "to " & s, proc (s: string): string = "not to " & s] var l = m.mapIt(capture([it], proc (s: string): string = it(s))) let r = l.mapIt(it("be")) -echo r[0] & ", or " & r[1] \ No newline at end of file +echo r[0] & ", or " & r[1] + +type O = object + v: int +var o = O(v: 1) +var execute: proc() +capture [o]: + execute = proc() = + echo o +execute() +o.v = -1 +execute()