summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2014-03-09 22:15:11 +0200
committerZahary Karadjov <zahary@gmail.com>2014-03-09 22:15:11 +0200
commit3dcf735482bed528f80614dca7a096f5e1a3aaa4 (patch)
tree6dcad46f73f3d8d1f364a1db521ec774585d82ef
parent29b7104a5330ebcb188243a271b4409e8613837b (diff)
downloadNim-3dcf735482bed528f80614dca7a096f5e1a3aaa4.tar.gz
fix #909
-rw-r--r--compiler/sem.nim4
-rw-r--r--compiler/semtempl.nim4
-rw-r--r--tests/template/tissue909.nim16
3 files changed, 23 insertions, 1 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 5ee46654e..ed4c4b093 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -139,6 +139,10 @@ proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
result = n.sym
internalAssert sfGenSym in result.flags
internalAssert result.kind == kind
+ # when there is a nested proc inside a template, semtmpl
+ # will assign a wrong owner during the first pass over the
+ # template; we must fix it here: see #909
+ result.owner = getCurrOwner()
else:
result = newSym(kind, considerAcc(n), getCurrOwner(), n.info)
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index 31624a97f..42268d44f 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -348,7 +348,9 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
of nkMethodDef:
result = semRoutineInTemplBody(c, n, skMethod)
of nkIteratorDef:
- result = semRoutineInTemplBody(c, n, n[namePos].sym.kind)
+ let kind = if hasPragma(n[pragmasPos], wClosure): skClosureIterator
+ else: skIterator
+ result = semRoutineInTemplBody(c, n, kind)
of nkTemplateDef:
result = semRoutineInTemplBody(c, n, skTemplate)
of nkMacroDef:
diff --git a/tests/template/tissue909.nim b/tests/template/tissue909.nim
new file mode 100644
index 000000000..5b57a3558
--- /dev/null
+++ b/tests/template/tissue909.nim
@@ -0,0 +1,16 @@
+import macros
+
+template baz() =
+ proc bar() =
+ var x = 5
+ iterator foo(): int {.closure.} =
+ echo x
+ var y = foo
+ discard y()
+
+macro test(): stmt =
+ result = getAst(baz())
+ echo(treeRepr(result))
+
+test()
+bar()