* Copy params which are captured in closures. Fixes #7048 * Forgot to emit a newline; minor adjustments to the test
This commit is contained in:
parent
cd65e5328d
commit
ca18dc2505
2 changed files with 63 additions and 1 deletions
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue