Skip to content

Commit

Permalink
fix #16516 method dispatch for sink args (#16594)
Browse files Browse the repository at this point in the history
* fix #16516

* fix comment

* Trigger build
  • Loading branch information
cooldome authored Jan 6, 2021
1 parent d721f5c commit 58b9191
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/cgmeth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ proc sameMethodBucket(a, b: PSym; multiMethods: bool): MethodResult =
while true:
aa = skipTypes(aa, {tyGenericInst, tyAlias})
bb = skipTypes(bb, {tyGenericInst, tyAlias})
if aa.kind == bb.kind and aa.kind in {tyVar, tyPtr, tyRef, tyLent}:
if aa.kind == bb.kind and aa.kind in {tyVar, tyPtr, tyRef, tyLent, tySink}:
aa = aa.lastSon
bb = bb.lastSon
else:
Expand Down
33 changes: 33 additions & 0 deletions tests/method/tmethod_issues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ discard """
output: '''
wof!
wof!
type A
type B
'''
"""

Expand Down Expand Up @@ -126,3 +128,34 @@ var obj2 = Class2()

obj1.test(obj2)
obj2.test(obj1)


# -------------------------------------------------------
# issue #16516

type
A = ref object of RootObj
x: int

B = ref object of A

method foo(v: sink A, lst: var seq[A]) {.base,locks:0.} =
echo "type A"
lst.add v

method foo(v: sink B, lst: var seq[A]) =
echo "type B"
lst.add v

proc main() =
let
a = A(x: 5)
b: A = B(x: 5)

var lst: seq[A]

foo(a, lst)
foo(b, lst)

main()

0 comments on commit 58b9191

Please sign in to comment.