work on closures continues; fixed #116

This commit is contained in:
Araq
2012-07-13 00:50:56 +02:00
parent dc8924e1a2
commit 8ce1c99d0d
3 changed files with 23 additions and 4 deletions

View File

@@ -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
View 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()

View File

@@ -11,7 +11,7 @@ version 0.9.0
New pragmas:
- ``hoist`` pragma for loop hoisting
- test & document ``byCopy`` pragma
- fix & document ``byCopy`` pragma
- document destructors
- ``borrow`` needs to take type classes into account