fix for template redefinition. test cases added.
This commit is contained in:
parent
d1d5fc8254
commit
6975ba401b
8 changed files with 99 additions and 15 deletions
|
|
@ -567,6 +567,19 @@ proc StrTableRawInsert(data: var TSymSeq, n: PSym) =
|
|||
assert(data[h] == nil)
|
||||
data[h] = n
|
||||
|
||||
proc SymTabReplaceRaw(data: var TSymSeq, prevSym: PSym, newSym: PSym) =
|
||||
assert prevSym.name.h == newSym.name.h
|
||||
var h: THash = prevSym.name.h and high(data)
|
||||
while data[h] != nil:
|
||||
if data[h] == prevSym:
|
||||
data[h] = newSym
|
||||
return
|
||||
h = nextTry(h, high(data))
|
||||
assert false
|
||||
|
||||
proc SymTabReplace*(t: var TStrTable, prevSym: PSym, newSym: PSym) =
|
||||
SymTabReplaceRaw(t.data, prevSym, newSym)
|
||||
|
||||
proc StrTableEnlarge(t: var TStrTable) =
|
||||
var n: TSymSeq
|
||||
newSeq(n, len(t.data) * growthFactor)
|
||||
|
|
|
|||
|
|
@ -1269,7 +1269,6 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
|||
if s != nil:
|
||||
case s.kind
|
||||
of skMacro:
|
||||
echo c.filename
|
||||
if c.filename.endsWith("hello.nim") and sfImmediate notin s.flags:
|
||||
result = semDirectOp(c, n, flags)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -191,14 +191,10 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
|||
result = n
|
||||
if n.sons[bodyPos].kind == nkEmpty:
|
||||
LocalError(n.info, errImplOfXexpected, s.name.s)
|
||||
var proto = SearchForProc(c, s, c.tab.tos-2) # -2 because we have a scope
|
||||
# open for parameters
|
||||
let curScope = c.tab.tos - 2 # -2 because we have a scope open for parameters
|
||||
var proto = SearchForProc(c, s, curScope)
|
||||
if proto == nil:
|
||||
# add identifier of template as a last step to not allow recursive templates:
|
||||
addInterfaceOverloadableSymAt(c, s, c.tab.tos - 2)
|
||||
else:
|
||||
# overwrite template
|
||||
proto.info = s.info
|
||||
proto.ast = s.ast
|
||||
proto.typ = s.typ
|
||||
proto.flags = s.flags
|
||||
SymTabReplace(c.tab.stack[curScope], proto, s)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue