summary refs log tree commit diff stats
path: root/tests/js/tclosures.nim
diff options
context:
space:
mode:
authorrec <44084068+recloser@users.noreply.github.com>2018-12-20 08:24:57 +0100
committerAndreas Rumpf <rumpf_a@web.de>2018-12-20 08:24:57 +0100
commitca18dc2505d3e3429860bef89d7e6a353cf935de (patch)
tree80f79e8838619ae7b527161f82bdff3c118fb727 /tests/js/tclosures.nim
parentcd65e5328dc82ca74a2905641a12e2c84a82d1de (diff)
downloadNim-ca18dc2505d3e3429860bef89d7e6a353cf935de.tar.gz
Make copies for params which are captured in closures. Fixes #7048 (#10050)
* Copy params which are captured in closures. Fixes #7048
* Forgot to emit a newline; minor adjustments to the test
Diffstat (limited to 'tests/js/tclosures.nim')
-rw-r--r--tests/js/tclosures.nim44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/js/tclosures.nim b/tests/js/tclosures.nim
index 659c60092..70037f4bf 100644
--- a/tests/js/tclosures.nim
+++ b/tests/js/tclosures.nim
@@ -49,3 +49,47 @@ for i in 1 .. 10:
 let results = runCallbacks()
 
 doAssert(expected == $results)
+
+block issue7048:
+  block:
+    proc foo(x: seq[int]): auto =
+      proc bar: int = x[1]
+      bar
+
+    var stuff = @[1, 2]
+    let f = foo(stuff)
+    stuff[1] = 321
+    doAssert f() == 2
+
+  block:
+    proc foo(x: tuple[things: string]; y: array[3, int]): auto =
+      proc very: auto = 
+        proc deeply: auto =
+          proc nested: (char, int) = (x.things[0], y[1])
+          nested
+        deeply
+      very()
+
+    var
+      stuff = (things: "NIM")
+      stuff2 = [32, 64, 96]
+    let f = foo(stuff, stuff2)
+    stuff.things = "VIM"
+    stuff2[1] *= 10
+    doAssert f()() == ('N', 64)
+    doAssert (stuff.things[0], stuff2[1]) == ('V', 640)
+
+  block:
+    proc foo(x: ptr string): auto =
+      proc bar(): int = len(x[])
+      bar
+    
+    var 
+      s1 = "xyz"
+      s2 = "stuff"
+      p = addr s1
+    
+    let f = foo(p)
+    p = addr s2
+    doAssert len(p[]) == 5
+    doAssert f() == 3
\ No newline at end of file