fixes #1944
This commit is contained in:
parent
d3a8d5b173
commit
5f6131cbdc
4 changed files with 36 additions and 13 deletions
|
|
@ -82,6 +82,16 @@ proc searchInScopes*(c: PContext, s: PIdent): PSym =
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
result = nil
|
result = nil
|
||||||
|
|
||||||
|
proc debugScopes*(c: PContext) {.deprecated.} =
|
||||||
|
var i = 0
|
||||||
|
for scope in walkScopes(c.currentScope):
|
||||||
|
echo "scope ", i
|
||||||
|
for h in 0 .. high(scope.symbols.data):
|
||||||
|
if scope.symbols.data[h] != nil:
|
||||||
|
echo scope.symbols.data[h].name.s
|
||||||
|
if i == 2: break
|
||||||
|
inc i
|
||||||
|
|
||||||
proc searchInScopes*(c: PContext, s: PIdent, filter: TSymKinds): PSym =
|
proc searchInScopes*(c: PContext, s: PIdent, filter: TSymKinds): PSym =
|
||||||
for scope in walkScopes(c.currentScope):
|
for scope in walkScopes(c.currentScope):
|
||||||
result = strTableGet(scope.symbols, s)
|
result = strTableGet(scope.symbols, s)
|
||||||
|
|
|
||||||
|
|
@ -113,12 +113,18 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||||
if s.typ.kind == tyStatic and s.typ.n != nil:
|
if s.typ.kind == tyStatic and s.typ.n != nil:
|
||||||
# XXX see the hack in sigmatch.nim ...
|
# XXX see the hack in sigmatch.nim ...
|
||||||
return s.typ.n
|
return s.typ.n
|
||||||
elif sfGenSym in s.flags and c.p.wasForwarded:
|
elif sfGenSym in s.flags:
|
||||||
# gensym'ed parameters that nevertheless have been forward declared
|
if c.p.wasForwarded:
|
||||||
# need a special fixup:
|
# gensym'ed parameters that nevertheless have been forward declared
|
||||||
let realParam = c.p.owner.typ.n[s.position+1]
|
# need a special fixup:
|
||||||
internalAssert realParam.kind == nkSym and realParam.sym.kind == skParam
|
let realParam = c.p.owner.typ.n[s.position+1]
|
||||||
return newSymNode(c.p.owner.typ.n[s.position+1].sym, n.info)
|
internalAssert realParam.kind == nkSym and realParam.sym.kind == skParam
|
||||||
|
return newSymNode(c.p.owner.typ.n[s.position+1].sym, n.info)
|
||||||
|
elif c.p.owner.kind == skMacro:
|
||||||
|
# gensym'ed macro parameters need a similar hack (see bug #1944):
|
||||||
|
var u = searchInScopes(c, s.name)
|
||||||
|
internalAssert u != nil and u.kind == skParam and u.owner == s.owner
|
||||||
|
return newSymNode(u, n.info)
|
||||||
result = newSymNode(s, n.info)
|
result = newSymNode(s, n.info)
|
||||||
# We cannot check for access to outer vars for example because it's still
|
# We cannot check for access to outer vars for example because it's still
|
||||||
# not sure the symbol really ends up being used:
|
# not sure the symbol really ends up being used:
|
||||||
|
|
|
||||||
|
|
@ -663,25 +663,22 @@ proc findEnforcedStaticType(t: PType): PType =
|
||||||
if t != nil: return t
|
if t != nil: return t
|
||||||
|
|
||||||
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
|
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
|
||||||
template addDecl(x) =
|
|
||||||
if sfGenSym notin x.flags: addDecl(c, x)
|
|
||||||
|
|
||||||
if kind == skMacro:
|
if kind == skMacro:
|
||||||
let staticType = findEnforcedStaticType(param.typ)
|
let staticType = findEnforcedStaticType(param.typ)
|
||||||
if staticType != nil:
|
if staticType != nil:
|
||||||
var a = copySym(param)
|
var a = copySym(param)
|
||||||
a.typ = staticType.base
|
a.typ = staticType.base
|
||||||
addDecl(a)
|
addDecl(c, a)
|
||||||
elif param.typ.kind == tyTypeDesc:
|
elif param.typ.kind == tyTypeDesc:
|
||||||
addDecl(param)
|
addDecl(c, param)
|
||||||
else:
|
else:
|
||||||
# within a macro, every param has the type PNimrodNode!
|
# within a macro, every param has the type PNimrodNode!
|
||||||
let nn = getSysSym"PNimrodNode"
|
let nn = getSysSym"PNimrodNode"
|
||||||
var a = copySym(param)
|
var a = copySym(param)
|
||||||
a.typ = nn.typ
|
a.typ = nn.typ
|
||||||
addDecl(a)
|
addDecl(c, a)
|
||||||
else:
|
else:
|
||||||
addDecl(param)
|
if sfGenSym notin param.flags: addDecl(c, param)
|
||||||
|
|
||||||
let typedescId = getIdent"typedesc"
|
let typedescId = getIdent"typedesc"
|
||||||
|
|
||||||
|
|
|
||||||
10
tests/macros/tmacro_in_template.nim
Normal file
10
tests/macros/tmacro_in_template.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
# bug #1944
|
||||||
|
import macros
|
||||||
|
|
||||||
|
template t(e: expr): stmt =
|
||||||
|
macro m(eNode: expr): stmt =
|
||||||
|
echo eNode.treeRepr
|
||||||
|
m e
|
||||||
|
|
||||||
|
t 5
|
||||||
Loading…
Add table
Add a link
Reference in a new issue