www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Nested interface

reply "Read Bixby" <rbixby hotmail.com> writes:
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
parent reply "Read Bixby" <rbixby hotmail.com> writes:
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
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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
parent "Read Bixby" <rbixby hotmail.com> writes:
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