fix #909
This commit is contained in:
parent
29b7104a53
commit
3dcf735482
3 changed files with 23 additions and 1 deletions
|
|
@ -139,6 +139,10 @@ proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
result = n.sym
|
result = n.sym
|
||||||
internalAssert sfGenSym in result.flags
|
internalAssert sfGenSym in result.flags
|
||||||
internalAssert result.kind == kind
|
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:
|
else:
|
||||||
result = newSym(kind, considerAcc(n), getCurrOwner(), n.info)
|
result = newSym(kind, considerAcc(n), getCurrOwner(), n.info)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,9 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
of nkMethodDef:
|
of nkMethodDef:
|
||||||
result = semRoutineInTemplBody(c, n, skMethod)
|
result = semRoutineInTemplBody(c, n, skMethod)
|
||||||
of nkIteratorDef:
|
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:
|
of nkTemplateDef:
|
||||||
result = semRoutineInTemplBody(c, n, skTemplate)
|
result = semRoutineInTemplBody(c, n, skTemplate)
|
||||||
of nkMacroDef:
|
of nkMacroDef:
|
||||||
|
|
|
||||||
16
tests/template/tissue909.nim
Normal file
16
tests/template/tissue909.nim
Normal file
|
|
@ -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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue