Skip to content

Commit

Permalink
Merge pull request #3666 from trustable-code/PR10
Browse files Browse the repository at this point in the history
Fix multimethods issue #3550
  • Loading branch information
Araq committed Dec 23, 2015
2 parents 86bb9d8 + 3c557a0 commit ebd14bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 1 addition & 4 deletions compiler/cgmeth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions tests/method/tmultim8.nim
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit ebd14bd

Please sign in to comment.