Comment #0 by Hexagonalstar64 — 2019-10-24T01:24:40Z
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
``
Comment #1 by robert.schadek — 2024-12-13T19:05:57Z