Merge pull request #4420 from yglukhov/closure-scope

Added closureScope template
This commit is contained in:
Andreas Rumpf 2016-07-04 10:41:48 +02:00 • committed by GitHub
commit 5f9da6b2ae
4 changed files with 44 additions and 3 deletions

View file

@ -1 +1,4 @@
discard """
output: ""
"""
import "../template/utemplates", "../closure/uclosures"

View file

@ -1,12 +1,23 @@
# This test is included from within tunittests
import unittest
test "loop variables are captured by copy":
test "loop variables are captured by ref":
var funcs: seq[proc (): int {.closure.}] = @[]
for i in 0..10:
let ii = i
funcs.add do -> int: return ii * ii
check funcs[0]() == 100
check funcs[3]() == 100
test "loop variables in closureScope are captured by copy":
var funcs: seq[proc (): int {.closure.}] = @[]
for i in 0..10:
closureScope:
let ii = i
funcs.add do -> int: return ii * ii
check funcs[0]() == 0
check funcs[3]() == 9