mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-18 23:11:36 +00:00
work on closures continues; fixed #116
This commit is contained in:
@@ -245,6 +245,7 @@ type
|
||||
# language; for interfacing with Objective C
|
||||
sfDiscardable # returned value may be discarded implicitely
|
||||
sfDestructor # proc is destructor
|
||||
sfByCopy # a variable is to be captured by value in a closure
|
||||
|
||||
TSymFlags* = set[TSymFlag]
|
||||
|
||||
@@ -264,9 +265,6 @@ const
|
||||
|
||||
sfShadowed* = sfInnerProc
|
||||
# a variable that was shadowed in some inner scope
|
||||
|
||||
sfByCopy* = sfBorrow
|
||||
# a variable is to be captured by value in a closure
|
||||
|
||||
sfHoist* = sfVolatile ## proc return value can be hoisted
|
||||
|
||||
|
||||
21
tests/run/tclosure3.nim
Normal file
21
tests/run/tclosure3.nim
Normal file
@@ -0,0 +1,21 @@
|
||||
discard """
|
||||
file: "tclosure3.nim"
|
||||
output: "success"
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
proc main =
|
||||
const n = 30
|
||||
for iterations in 0..50_000:
|
||||
var s: seq[proc(): int {.closure.}] = @[]
|
||||
for i in 0 .. n-1:
|
||||
let ii = i
|
||||
s.add(proc(): int = return ii*ii)
|
||||
for i in 0 .. n-1:
|
||||
let val = s[i]()
|
||||
if val != i*i: echo "bug ", val
|
||||
|
||||
if getOccupiedMem() > 3000_000: quit("still a leak!")
|
||||
echo "success"
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user