generic multi-methods should work now

This commit is contained in:
Andreas Rumpf 2016-07-28 20:23:16 +02:00
commit f5fa5dae85
9 changed files with 67 additions and 21 deletions

View file

@ -1352,7 +1352,19 @@ proc semMethod(c: PContext, n: PNode): PNode =
# macros can transform methods to nothing:
if namePos >= result.safeLen: return result
var s = result.sons[namePos].sym
if not isGenericRoutine(s):
if isGenericRoutine(s):
let tt = s.typ
var foundObj = false
for col in countup(0, sonsLen(tt)-1):
let t = tt.sons[col]
if t != nil and t.kind == tyGenericInvocation:
var x = skipTypes(t.sons[0], {tyVar, tyPtr, tyRef, tyGenericInst, tyGenericInvocation, tyGenericBody})
if x.kind == tyObject:
foundObj = true
x.methods.safeAdd((col,s))
if not foundObj:
message(n.info, warnDeprecated, "generic method not attachable to object type")
else:
# why check for the body? bug #2400 has none. Checking for sfForward makes
# no sense either.
# and result.sons[bodyPos].kind != nkEmpty: