fixes a multimethod regression

This commit is contained in:
Andreas Rumpf 2017-02-24 13:02:36 +01:00
commit f8914cc3b0
3 changed files with 33 additions and 8 deletions

View file

@ -35,15 +35,18 @@ proc genConv(n: PNode, d: PType, downcast: bool): PNode =
else:
result = n
proc getDispatcher*(s: PSym): PSym =
## can return nil if is has no dispatcher.
let dispn = lastSon(s.ast)
if dispn.kind == nkSym:
let disp = dispn.sym
if sfDispatcher in disp.flags: result = disp
proc methodCall*(n: PNode): PNode =
result = n
# replace ordinary method by dispatcher method:
let dispn = lastSon(result.sons[0].sym.ast)
if dispn.kind == nkSym:
let disp = dispn.sym
if sfDispatcher notin disp.flags:
localError(n.info, "'" & $result & "' lacks a dispatcher")
return
let disp = getDispatcher(result.sons[0].sym)
if disp != nil:
result.sons[0].sym = disp
# change the arguments to up/downcasts to fit the dispatcher's parameters:
for i in countup(1, sonsLen(result)-1):