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

Multiple inheritance covariance breaks vtable dispatch #19632

Open
dlangBugzillaToGithub opened this issue Oct 24, 2019 · 0 comments
Open

Multiple inheritance covariance breaks vtable dispatch #19632

dlangBugzillaToGithub opened this issue Oct 24, 2019 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

Hexagonalstar64 reported this on 2019-10-24T01:24:40Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=20312

CC List

Description

Interface covariance causes incorrect vtable lookups when the interfaces have multiple inheritance as illustrated by this sample code.
``
interface A {
    int x();
}

interface B : A{
    int y();
}

interface C : A {
    int z();
}

class Impl : B, C{
    override:
    int x() { return 0; }
    int y() { return 1; }
    int z() { return 2; }
}


interface GetA{
    A get();
}

interface GetB : GetA{
    B get();
}

interface GetC : GetA {
    C get();
}

class ImplGet : GetB, GetC{
    Impl impl;
    this(Impl impl){
        this.impl = impl;
    }
    override
    Impl get(){
        return impl;
    }
}

import std.stdio;

void main(){
    Impl impl = new Impl();
    C c = impl;
    
    ImplGet implget = new ImplGet(impl);
    GetC getc = implget;
    C c2 = getc.get;
    
    writeln(c.z); // prints 2 as expected
    writeln(c2.z); // prints 1 !
}
``

``
$ dmd --version
DMD64 D Compiler v2.088.1
Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved written by Walter Bright
$ dmd bug
$ ./bug
2
1
``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant