www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4647] New: Cannot explicitly call final interface method, ambiguous calls allowed

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4647

           Summary: Cannot explicitly call final interface method,
                    ambiguous calls allowed
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2010-08-15
10:32:38 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 15 2010
next sibling parent Lukasz Wrzosek <dprogramms gmail.com> writes:
Dnia 2010-08-15, o godz. 17:32:42
d-bugmail puremagic.com napisa=B3(a):

 http://d.puremagic.com/issues/show_bug.cgi?id=3D4647
=20
            Summary: Cannot explicitly call final interface method,
                     ambiguous calls allowed
            Product: D
            Version: D2
           Platform: Other
         OS/Version: Windows
             Status: NEW
           Severity: normal
           Priority: P2
          Component: DMD
         AssignedTo: nobody puremagic.com
         ReportedBy: andrej.mitrovich gmail.com
=20
=20
 --- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com>
 2010-08-15 10:32:38 PDT --- Code on 2.048:
=20
 import std.stdio;
=20
 interface Timer
 {
     final void run() { writeln("Timer.run()"); };
 }
=20
 interface Application
 {
     final void run() { writeln("Application.run()"); };
 }
=20
 class TimedApp : Timer, Application
 {
 }
=20
 import std.stdio;
=20
 void main()
 {
     auto app =3D 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
 }
=20
 The comments state what happens.
=20
 Note that if I changed the order of the TimedApp signature like so:
=20
 class TimedApp : Application, Timer
=20
 then the Application's run() method would be called instead of
 Timer's in the app.run() call.
=20
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.
Aug 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4647



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2010-08-15
12:04:34 PDT ---
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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4647


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla kyllingen.net
            Summary|Cannot explicitly call      |TDPL: Cannot explicitly
                   |final interface method,     |call final interface
                   |ambiguous calls allowed     |method, ambiguous calls
                   |                            |allowed
         OS/Version|Windows                     |All
           Severity|normal                      |major


--- Comment #2 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2010-08-16
00:05:38 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4647


Kasumi Hanazuki <k.hanazuki gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool gmx.de


--- Comment #3 from Kasumi Hanazuki <k.hanazuki gmail.com> 2011-10-25 12:38:15
PDT ---
*** Issue 6680 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 25 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4647


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #5 from Walter Bright <bugzilla digitalmars.com> 2011-12-25
16:30:01 PST ---
https://github.com/D-Programming-Language/dmd/commit/4d9f2e7fd86fcdf9cbfec5c9bbad304ed125132d

https://github.com/D-Programming-Language/dmd/commit/d0fcaa80b468c455ce4b25a7af6c61fcaf749ee1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 25 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4647


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ary esperanto.org.ar


--- Comment #6 from yebblies <yebblies gmail.com> 2012-01-31 13:34:12 EST ---
*** Issue 3759 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2012