www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5060] New: Order of interface implementations affects code

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

           Summary: Order of interface implementations affects code
           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-10-15
12:10:27 PDT ---
Code:

interface Foo
{
   final void run() { writeln("foo"); }
}

interface Bar
{
   final void run() { writeln("bar"); }
}

class One : Foo, Bar
{
}

class Two : Bar, Foo
{
}

void main()
{
   with (new One)
   {
       run();  // writes foo
   }

   with (new Two)
   {
       run();  // writes bar
   }
}

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



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-17
13:05:41 PDT ---
P.S.: OP code is missing an import to std.stdio.

Perhaps the right way to implement this is to simply allow shadowing via an
alias declaration:

class One : Foo, Bar
{
    alias Foo.run run;  // pick Foo's run, hide Bar's run
}

class Two : Bar, Foo
{
    alias Bar.run run;  // do the opposite
}

Otherwise, emit a compiler error. Thoughts?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 17 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5060



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-17
13:07:28 PDT ---
(In reply to comment #1)
 Otherwise, emit a compiler error.
I meant emit the error at the call site when "run" is called but both interfaces define the function with this name. Either the class developer introduces the alias, or the user could do: object.Foo.run(); // explicitly call this interface function object.Bar.run(); // ditto -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 17 2013