digitalmars.D.learn - Nested interface
- Read Bixby (37/37) Apr 01 2012 I was working on a small personal project, and ran across
- Read Bixby (21/58) Apr 01 2012 Hm, I guess it's much simpler than that. I must not be
- Timon Gehr (5/24) Apr 01 2012 This is a compiler bug. It works if 'Interface' is changed to an
- Read Bixby (2/34) Apr 01 2012
I was working on a small personal project, and ran across something I think might (or might not) be a bug. I'm posting in this particular group just in case it's a restriction somewhere that I just don't know about, or maybe just the way that covariance gets resolved. The obvious workaround is to return NestedInterface from the two methods of the derived class rather than NestedImplementation, but I was kind of surprised it didn't compile (in the actual code, both the nested interface and the nested implementation were called "Node" which was stupid on my part). I got the error message: "Error: class Implementation.NestedImplementation ambiguous virtual function getNext" Is this something anyone is likely to care about? shared interface Interface { public static shared interface NestedInterface { public shared(NestedInterface) getNext(); public shared(const(NestedInterface)) getNext() const; } } shared class Implementation : Interface { public static shared class NestedImplementation : Interface.NestedInterface { public override shared(NestedImplementation) getNext() { return null; } public override shared(const(NestedImplementation)) getNext() const { return null; } } }
Apr 01 2012
Hm, I guess it's much simpler than that. I must not be understanding something about covariance. The following code produces the same error message (it has nothing to do with nestedness or shared classes): interface Interface { Interface getNext(); const(Interface) getNext() const; } class Implementation : Interface { Implementation getNext() { return null; } const(Implementation) getNext() const { return null; } } On Sunday, 1 April 2012 at 16:40:55 UTC, Read Bixby wrote:I was working on a small personal project, and ran across something I think might (or might not) be a bug. I'm posting in this particular group just in case it's a restriction somewhere that I just don't know about, or maybe just the way that covariance gets resolved. The obvious workaround is to return NestedInterface from the two methods of the derived class rather than NestedImplementation, but I was kind of surprised it didn't compile (in the actual code, both the nested interface and the nested implementation were called "Node" which was stupid on my part). I got the error message: "Error: class Implementation.NestedImplementation ambiguous virtual function getNext" Is this something anyone is likely to care about? shared interface Interface { public static shared interface NestedInterface { public shared(NestedInterface) getNext(); public shared(const(NestedInterface)) getNext() const; } } shared class Implementation : Interface { public static shared class NestedImplementation : Interface.NestedInterface { public override shared(NestedImplementation) getNext() { return null; } public override shared(const(NestedImplementation)) getNext() const { return null; } } }
Apr 01 2012
On 04/01/2012 08:13 PM, Read Bixby wrote:Hm, I guess it's much simpler than that. I must not be understanding something about covariance. The following code produces the same error message (it has nothing to do with nestedness or shared classes): interface Interface { Interface getNext(); const(Interface) getNext() const; } class Implementation : Interface { Implementation getNext() { return null; } const(Implementation) getNext() const { return null; } }This is a compiler bug. It works if 'Interface' is changed to an abstract class. Please report this issue to the bug tracker: http://d.puremagic.com/issues/
Apr 01 2012
Thanks; entered as issue 7807. On Sunday, 1 April 2012 at 20:17:09 UTC, Timon Gehr wrote:On 04/01/2012 08:13 PM, Read Bixby wrote:Hm, I guess it's much simpler than that. I must not be understanding something about covariance. The following code produces the same error message (it has nothing to do with nestedness or shared classes): interface Interface { Interface getNext(); const(Interface) getNext() const; } class Implementation : Interface { Implementation getNext() { return null; } const(Implementation) getNext() const { return null; } }This is a compiler bug. It works if 'Interface' is changed to an abstract class. Please report this issue to the bug tracker: http://d.puremagic.com/issues/
Apr 01 2012