Merge pull request #3666 from trustable-code/PR10

Fix multimethods issue #3550
This commit is contained in:
Andreas Rumpf
2015-12-24 00:13:16 +01:00
2 changed files with 20 additions and 4 deletions

View File

@@ -19,10 +19,7 @@ proc genConv(n: PNode, d: PType, downcast: bool): PNode =
if (source.kind == tyObject) and (dest.kind == tyObject):
var diff = inheritanceDiff(dest, source)
if diff == high(int):
# see bug #3550 which triggers it. XXX This is a hack but I don't know yet
# how the real fix looks like:
localError(n.info, "there is no subtype relation between " &
typeToString(d) & " and " & typeToString(n.typ))
# no subtype relation, nothing to do
result = n
elif diff < 0:
result = newNodeIT(nkObjUpConv, n.info, d)

19
tests/method/tmultim8.nim Normal file
View File

@@ -0,0 +1,19 @@
# bug #3550
type
BaseClass = ref object of RootObj
Class1 = ref object of BaseClass
Class2 = ref object of BaseClass
method test(obj: Class1, obj2: BaseClass) =
discard
method test(obj: Class2, obj2: BaseClass) =
discard
var obj1 = Class1()
var obj2 = Class2()
obj1.test(obj2)
obj2.test(obj1)