From aa36e73ecf1e09367a5e94de6c3af488449eb4f6 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 25 Oct 2015 02:22:50 +0100 Subject: [PATCH] fixes #3431, fixes #3370, fixes #3468 --- compiler/cgmeth.nim | 7 +++--- tests/method/tmultim7.nim | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 tests/method/tmultim7.nim diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index 9642e91220..3c2c51b76a 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -66,15 +66,16 @@ proc sameMethodBucket(a, b: PSym): MethodResult = bb = bb.lastSon else: break - if sameType(aa, bb): discard + if sameType(aa, bb): + if aa.kind == tyObject and result != Invalid: result = Yes elif aa.kind == tyObject and bb.kind == tyObject: let diff = inheritanceDiff(bb, aa) - if diff < 0: discard "Ok" + if diff < 0: + if result != Invalid: result = Yes elif diff != high(int): result = Invalid else: return No - if result != Invalid: result = Yes proc attachDispatcher(s: PSym, dispatcher: PNode) = var L = s.ast.len-1 diff --git a/tests/method/tmultim7.nim b/tests/method/tmultim7.nim new file mode 100644 index 0000000000..7a88596792 --- /dev/null +++ b/tests/method/tmultim7.nim @@ -0,0 +1,48 @@ + +# bug #3431 + +type + Lexer = object + buf*: string + pos*: int + lastchar*: char + + ASTNode = object + +method init*(self: var Lexer; buf: string) {.base.} = + self.buf = buf + self.pos = 0 + self.lastchar = self.buf[0] + +method init*(self: var ASTNode; val: string) = + discard + + +# bug #3370 +type + RefTestA*[T] = ref object of RootObj + data*: T + +method tester*[S](self: S): bool = + true + +type + RefTestB* = RefTestA[(string, int)] + +method tester*(self: RefTestB): bool = + true + +type + RefTestC = RefTestA[string] + +method tester*(self: RefTestC): bool = + false + + +# bug #3468 + +type X = ref object of RootObj +type Y = ref object of RootObj + +method draw*(x: X) {.base.} = discard +method draw*(y: Y) {.base.} = discard