private mixin function

Regan Heath regan at netwin.co.nz
Wed Apr 12 04:18:18 PDT 2006


On Tue, 11 Apr 2006 16:03:36 -0400, Jarrett Billingsley  
<kb3ctd2 at yahoo.com> wrote:
> "Frank Benoit" <benoit__ at __tionex.de> wrote in message
> news:e1gh7m$2btt$1 at digitaldaemon.com...
>> Never mind. Calling it with
>> m1.func();
>> works.
>
> Hahaha, it's two bugs canceling each other out (maybe).

I have a feeling it's related. I think mixins have some problems which  
should be addressed, or at the very least cleared up in the docs. Let me  
elaborate... :)

In this case a 'MixinIdentifier' has been given 'm1':

mixin m!(byte) m1;

The docs say: "If a mixin has a MixinIdentifier, it can be used to  
disambiguate" which, isn't exactly what we're using it for, but it does  
seem to solve the problem. Then again, maybe this is the same bug as you  
mention where a private member in another module can be accessed with it's  
full name.

I think part of the problem is that "A mixin has its own scope ...", this  
was taken a little out of context, see:
   http://www.digitalmars.com/d/mixin.html

It suggests to me that mixin has a scope (especially when you give it an  
identifier like 'm1'). If it has a scope, and that scope is m1, then it  
makes sense that need to call the function with m1.func();

That said, earlier in the docs it says "The declarations in a mixin are  
'imported' into the surrounding scope" and "It is analogous to cutting and  
pasting the body of the template into the location of the mixin", if those  
statements were true then this code should work:

template m(T){
	private void func() {}
}

class C{
	mixin m!(byte);
	
	public this(){
		func(); // error: func is private
	}
}

(note, no identifier) but it doesn't. It gives the same error as you had  
before. As there is no mixin identifier there is no solution here.

I've had this exact problem with them in the past, trying to mix private  
declarations into a class just plain doesn't work. Instead it results in  
something akin to a derived class, where the base had private members.  
They're just plain inaccessable, as you've found.

I would love to see this cleaned up.

Regan



More information about the Digitalmars-d-learn mailing list