Created attachment 1302
[email protected](38): funcA not called
In situation with multiple inheritance in realization, like in attachment,
there is a problem: functions (funcA) of the first interface (IFaceA) isn't
callable, of which inherited the intermediate interface (IFaceA1)
compiler: DMD64 D Compiler v2.064-devel-37e15ab
OS: Linux 3.11.6-200.fc19.x86_64
Comment #1 by andrej.mitrovich — 2013-12-22T01:12:16Z
Comment #2 by andrej.mitrovich — 2013-12-22T01:13:38Z
(In reply to comment #1)
> Reduced:
What's worrying is that func2() ends up being called:
-----
interface I1 { void func1(); }
interface I2 { void func2(); }
interface I3 : I1 { }
interface I4 : I2, I3 { }
import std.stdio;
class Test : I4
{
void func1() { check = true; }
void func2() { assert(0); }
bool check;
}
void main()
{
I4 sub = new Test;
sub.func1(); // triggers assertion (func2 called)
}
-----
Comment #3 by maxim — 2013-12-22T01:33:15Z
Note, if order of interfaces in derivative list is changed, program runs fine.
interface I4 : I2, I3 { } => interface I4 : I3, I2 { }
Perhaps compiler puts func2() before func1() in vitrual table, after reading Test class definition assumes that func1() is placed before func2(), so the second function is called.
Comment #4 by k.hara.pg — 2015-07-18T13:57:09Z
(In reply to Andrej Mitrovic from comment #2)
> sub.func1(); // triggers assertion (func2 called)
It's translated to (cast(I1)sub).func1() and a dynamic cast from I4 to I1 occurs to take the vtbl of I1. Then the issue 2013 happens.
*** This issue has been marked as a duplicate of issue 2013 ***