Nested interface

2012-04-01 Thread Read Bixby
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;
}
}
}



Re: Nested interface

2012-04-01 Thread Read Bixby
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;
}
}
}





Re: Nested interface

2012-04-01 Thread Read Bixby

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/





question about AutoImplement_Helper (and a couple of others)

2011-04-15 Thread Read Bixby
I'm a bit new with the D programming language, so I figured this
would be the right place to ask a few questions that have been
piling up.

So let's start.  First, I recently found the AutoImplement class
while I was trying to build a Proxy object.  It seemed like an
interesting thing to try, though it may not be a good way to manage
asynchronously created resources (which is what I was planning to
use it for).

At any rate, since AutoImplement is a class already, and I have this
thing about not deriving from concrete classes, I decided use
AutoImplement_Helper instead.  I needed a proxied object, after all,
so I needed to be able to manipulate the class definition.  It was
only after doing so that I noticed it was marked private, and thus
presumably not intended for public consumption (and I have no idea
why it even compiles).

private shared class Proxy(InterfaceType) if (is (InterfaceType ==
interface)) : public InterfaceType
{
private alias AutoImplement_Helper!(autoImplement_helper_,
InterfaceType, InterfaceType, GeneratePassthroughMethod,
isAbstractFunction) autoImplement_helper_;
public mixin(autoImplement_helper_.code);

public shared static this()
{
s_proxy = new BlackHole!(InterfaceType);
}

public this()
{
m_instance = s_proxy;
}

public void setProxiedInstance(shared(InterfaceType)
instance)
{
m_instance = instance;
}

private static shared(InterfaceType) s_proxy;

private InterfaceType m_instance;
}

private template GeneratePassthroughMethod(InterfaceType, method...)
{
public const(string) GeneratePassthroughMethod =
__traits(getMember, this.m_instance, __traits(identifier, self))
(args);;
}

Is there another way (that I just haven't seen) to do what I'm
trying to do?  I could just bite the bullet and derive my proxy from
AutoImplement, but I thought I'd ask first.

Next, you may have noticed that it's a shared class.  I wanted to
make sure that the assignment I'm doing in the setProxiedInstance()
method will be atomic, and that reading the variable will also be
atomic.

My third question is about attributes.  As far as I can tell, D has
no user defined attributes, correct?  I was making myself a unit
test framework (with simple reporting, encapsulation of unit tests
as methods, and assertion tools).  I was hoping to perform automatic
registration of the individual unit tests, but the best I could
manage was compile-time detection of methods starting with test,
and this feels like a hack.  I would prefer to mark the methods
explicitly in some way.  Does anyone know of a way to do this?

Thanks for your time.