diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-07-28 20:23:16 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-07-28 20:23:24 +0200 |
commit | f5fa5dae85030510156298477cefe189f44524dc (patch) | |
tree | f8bfd2cb011d7b35726e7f629d8e0112965089db /compiler/semstmts.nim | |
parent | 34afaeeeddce3c96d0798c44ea4f4fcca93a5fd0 (diff) | |
download | Nim-f5fa5dae85030510156298477cefe189f44524dc.tar.gz |
generic multi-methods should work now
Diffstat (limited to 'compiler/semstmts.nim')
-rw-r--r-- | compiler/semstmts.nim | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 79581e4cb..1f076aa31 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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: |