Code on 2.048: import std.stdio; interface Timer { final void run() { writeln("Timer.run()"); }; } interface Application { final void run() { writeln("Application.run()"); }; } class TimedApp : Timer, Application { } import std.stdio; void main() { auto app = new TimedApp; app.Timer.run(); // error, no Timer property app.Application.run(); // error, no Application property app.run(); // This would call Timer.run() if the two calls // above were commented out } The comments state what happens. Note that if I changed the order of the TimedApp signature like so: class TimedApp : Application, Timer then the Application's run() method would be called instead of Timer's in the app.run() call.
Comment from Lukasz Wrzosek >This: > app.Timer.run(); // error, no Timer property > app.Application.run(); // error, no Application property > >probably should be: > (cast(Timer)app).run(); > (cast(Application)app).run(); > >But app.run() is still ambiguous - should not compile. I don't see why I would need a cast. I can explicitly call methods from inherited classes, like so: import std.stdio; class Base { void test() { writeln("Base.test()"); }; } class Derived : Base { override void test() { writeln("Derived.test()");} } class SecondDerived : Derived { } void main() { auto var = new SecondDerived; var.Base.test(); // calls Base.test() var.Derived.test(); // calls Derived.test() } So why shouldn't I be able to do the same with interfaces? TDPL allows it, I think it should be allowed in DMD.
I don't have TDPL in front of me right now, but I, too, seem to remember that this should be allowed. Raising the priority of this.
*** Issue 6680 has been marked as a duplicate of this issue. ***
Patch for app.Timer.run() / app.Application.run(): https://github.com/D-Programming-Language/dmd/pull/578 ---- (In reply to comment #0) > Note that if I changed the order of the TimedApp signature like so: > > class TimedApp : Application, Timer > > then the Application's run() method would be called instead of Timer's in the > app.run() call. I think the behavior is correct, because name lookup is depth-first. Then app.run() depends on the order of derived bases.
https://github.com/D-Programming-Language/dmd/commit/4d9f2e7fd86fcdf9cbfec5c9bbad304ed125132d https://github.com/D-Programming-Language/dmd/commit/d0fcaa80b468c455ce4b25a7af6c61fcaf749ee1
*** Issue 3759 has been marked as a duplicate of this issue. ***
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル