Am Tue, 19 Mar 2013 17:51:52 -0400 schrieb "Steven Schveighoffer" <[email protected]>:
> On Sun, 17 Mar 2013 09:59:03 -0400, Maxim Fomin > <[email protected]> wrote: > > > Actually it was http://d.puremagic.com/issues/show_bug.cgi?id=4589 > > I don't think this is the same problem. > > I modified the program a bit: > > import core.stdc.stdio; > interface Timer > { > final int run() { printf("Timer.run(), this=%x\n", > cast(void*)this); fun(); return 1;} > int fun(); > } > interface Application > { > final int run() { printf("Application.run(), this=%x\n", > cast(void *)this); fun(); return 2; }; > int fun(); > } > > class TimedApp : Timer, Application > { > int fun() > { > printf("TimedApp.fun(), this=%x\n", cast(void*)this); > return 0; > } > } > > void main() > { > auto app = new TimedApp; > (cast(Application)app).run(); > (cast(Timer)app).run(); > app.Application.run(); > app.Timer.run(); > } > > New output: > > Application.run(), this=10007ff8 > TimedApp.fun(), this=10007fe0 > Timer.run(), this=10007ff0 > TimedApp.fun(), this=10007fe0 > Application.run(), this=10007fe0 > Timer.run(), this=10007fe0 > > Note that Application.run() is given the interface pointer 10007ff8, > whereas the *true* object pointer is 10007fe0. This is normal and > expected. > > However, in the *last* call to Application.run (and Timer.run), it's > given the pointer 10007fe0, the true object pointer. This gives it > the completely WRONG vtable to use for calling fun. I think this is > different than the bug I posted. It may be related, I don't know. > > If this bug is not already reported, it should be. > > -Steve I'll report it soon and I already have a bug fix. (The compiler indeed always passed the object pointer. This is valid for base classes, but not for interfaces. Adding an isInterface check + CastExpression solves this issue)
