Thread overview
[Issue 5344] New: Interface Inheritance Problem
Dec 12, 2010
Mandeep Singh Brar
Dec 19, 2010
Andrej Mitrovic
Dec 19, 2010
Andrej Mitrovic
Dec 19, 2010
Andrej Mitrovic
December 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5344

           Summary: Interface Inheritance Problem
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: mandeep@brars.co.in


--- Comment #0 from Mandeep Singh Brar <mandeep@brars.co.in> 2010-12-12 09:32:28 PST ---
The following code does not compile.

import std.stdio;
interface A {
    public void a(int l);
}
class ACl:A {
    public void a(int l) {
        writeln("Hello a");
    }
}

interface B: public A {
    public void a(string l, int k);
}

class BCl: ACl, B {
    public void a(string l, int k) {
        writeln("Hello B.a", l, k);
    }
}


int main() {
    B b = new BCl();
    b.a(1);
    return 0;
}

However changing the second line of main() to (cast(A)b).a(1) makes it work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5344


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-12-19 10:17:49 PST ---
If I'm not mistaked:
B b = new BCl();

means the object b has a static type B, and the dynamic type BCl. Which means you can only call methods defined by the B interface. This is probably discussed more in TDPL, but I'd have to check it again because I'm not sure..

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5344



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-12-19 10:18:32 PST ---
Oh I see the problem now, B inherits from A, I missed that line.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5344



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-12-19 10:28:32 PST ---
Yeah the only way this compiles is if you use the A type:
A b = new BCl();
b.a(1);

I don't see why using a B object wouldn't work. Bug, i guess..

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