You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
``
The text was updated successfully, but these errors were encountered:
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 ``The text was updated successfully, but these errors were encountered: