Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic dispatch doesn't work properly when types are generic #2686

Closed
adlertz opened this issue May 10, 2015 · 3 comments
Closed

Dynamic dispatch doesn't work properly when types are generic #2686

adlertz opened this issue May 10, 2015 · 3 comments
Labels
Documentation Content Related to documentation content (not generation). Methods

Comments

@adlertz
Copy link

adlertz commented May 10, 2015

type X = object of RootObj
type Y[T] = object of X
    op*: T
type Z = object of X
    op*: int

proc newY[T](op: T): ref Y[T] =
    new(result)
    result.op = op

proc newZ(op: int): ref Z =
    new(result)
    result.op = op

proc y(): ref X =
    newY(6)

proc z(): ref X =
    newZ(5)

method desc(i: ref X): string =
    quit "Must override"

method desc[T](i: ref Y[T]): string =
    $i.op

method desc(i: ref Z): string =
    $i.op

let i1 = z()
let i2 = y()
echo i1.desc() # prints "5"
echo i2.desc() # exits with "Must override", should print "6"
@Araq Araq added the Methods label May 12, 2015
@Araq
Copy link
Member

Araq commented May 12, 2015

Quite sure this is only a quirk that needs to be finally documented.

@Araq Araq added the Documentation Content Related to documentation content (not generation). label May 12, 2015
@adlertz
Copy link
Author

adlertz commented May 12, 2015

You mean this is the intended behaviour?

@Araq
Copy link
Member

Araq commented Oct 20, 2016

Since 0.15 the behaviour changed and it should now work as "expected" for some value of "expected".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Content Related to documentation content (not generation). Methods
Projects
None yet
Development

No branches or pull requests

2 participants