www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - alias this question

reply Olli Aalto <oaalto gmail.com> writes:
I encountered a problem with alias this, when the aliased member is 
private. I'm using the latest dmd2. It reports the follwing:
src\main.d(14): Error: struct K.K member s is not accessible

If I change the private modifier on the s member to public it works.

Is this as intended, or a bug?

O.
Feb 13 2011
next sibling parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Olli Aalto <oaalto gmail.com> wrote:

 I encountered a problem with alias this, when the aliased member is
 private. I'm using the latest dmd2. It reports the follwing:
 src\main.d(14): Error: struct K.K member s is not accessible

 If I change the private modifier on the s member to public it works.

 Is this as intended, or a bug?
This is intended. alias this (and any other alias) act as simple rewrites to the aliased symbol, and does not change their protection level. certainly does describe it in general. http://d.puremagic.com/issues/show_bug.cgi?id=4533 -- Simen
Feb 13 2011
parent Olli Aalto <oaalto gmail.com> writes:
On 13.2.2011 19:40, Simen kjaeraas wrote:
 Olli Aalto <oaalto gmail.com> wrote:

 I encountered a problem with alias this, when the aliased member is
 private. I'm using the latest dmd2. It reports the follwing:
 src\main.d(14): Error: struct K.K member s is not accessible

 If I change the private modifier on the s member to public it works.

 Is this as intended, or a bug?
This is intended. alias this (and any other alias) act as simple rewrites to the aliased symbol, and does not change their protection level.
Pity. Would have been nice, now it's just one pretty useless feature at the end of a list of features for the language. O.
Feb 13 2011
prev sibling next sibling parent spir <denis.spir gmail.com> writes:
On 02/13/2011 05:30 PM, Olli Aalto wrote:
 I encountered a problem with alias this, when the aliased member is private.
 I'm using the latest dmd2. It reports the follwing:
 src\main.d(14): Error: struct K.K member s is not accessible

 If I change the private modifier on the s member to public it works.

 Is this as intended, or a bug?
Dunno, lets me wonder: what are use cases of alias this on a public member? I mean, on a member that /must/ remain private. Then, it's just syntactic sugar, which is good, but why wrap it into an object? In my mind, the typical use case is precisely a wrapper struct around something that, so-to-say, "naturally" ends up private. Denis -- _________________ vita es estrany spir.wikidot.com
Feb 13 2011
prev sibling parent reply Christopher Nicholson-Sauls <ibisbasenji gmail.com> writes:
On 02/13/11 10:30, Olli Aalto wrote:
 I encountered a problem with alias this, when the aliased member is
 private. I'm using the latest dmd2. It reports the follwing:
 src\main.d(14): Error: struct K.K member s is not accessible
 
 If I change the private modifier on the s member to public it works.
 
 Is this as intended, or a bug?
 
 O.
 
There is actually an alternative, but I believe I remember it being said that this would go away. In the meantime, I think it still works and maybe it could be saved. The alternative is to define a method opDot() which returns the entity to forward the call to. Check out std.typecons:Unique for an example. -- Chris N-S
Feb 16 2011
parent reply Jacob Carlborg <doob me.com> writes:
On 2011-02-16 20:42, Christopher Nicholson-Sauls wrote:
 On 02/13/11 10:30, Olli Aalto wrote:
 I encountered a problem with alias this, when the aliased member is
 private. I'm using the latest dmd2. It reports the follwing:
 src\main.d(14): Error: struct K.K member s is not accessible

 If I change the private modifier on the s member to public it works.

 Is this as intended, or a bug?

 O.
There is actually an alternative, but I believe I remember it being said that this would go away. In the meantime, I think it still works and maybe it could be saved. The alternative is to define a method opDot() which returns the entity to forward the call to. Check out std.typecons:Unique for an example. -- Chris N-S
Isn't opDot deprecated in favor of opDispatch? -- /Jacob Carlborg
Feb 17 2011
parent reply spir <denis.spir gmail.com> writes:
On 02/17/2011 11:41 AM, Jacob Carlborg wrote:
 On 2011-02-16 20:42, Christopher Nicholson-Sauls wrote:
 On 02/13/11 10:30, Olli Aalto wrote:
 I encountered a problem with alias this, when the aliased member is
 private. I'm using the latest dmd2. It reports the follwing:
 src\main.d(14): Error: struct K.K member s is not accessible

 If I change the private modifier on the s member to public it works.

 Is this as intended, or a bug?

 O.
There is actually an alternative, but I believe I remember it being said that this would go away. In the meantime, I think it still works and maybe it could be saved. The alternative is to define a method opDot() which returns the entity to forward the call to. Check out std.typecons:Unique for an example. -- Chris N-S
Isn't opDot deprecated in favor of opDispatch?
I personly need opDot, to customize member access ; not (only) method call. Denis -- _________________ vita es estrany spir.wikidot.com
Feb 17 2011
parent reply Jacob Carlborg <doob me.com> writes:
On 2011-02-17 11:54, spir wrote:
 On 02/17/2011 11:41 AM, Jacob Carlborg wrote:
 On 2011-02-16 20:42, Christopher Nicholson-Sauls wrote:
 On 02/13/11 10:30, Olli Aalto wrote:
 I encountered a problem with alias this, when the aliased member is
 private. I'm using the latest dmd2. It reports the follwing:
 src\main.d(14): Error: struct K.K member s is not accessible

 If I change the private modifier on the s member to public it works.

 Is this as intended, or a bug?

 O.
There is actually an alternative, but I believe I remember it being said that this would go away. In the meantime, I think it still works and maybe it could be saved. The alternative is to define a method opDot() which returns the entity to forward the call to. Check out std.typecons:Unique for an example. -- Chris N-S
Isn't opDot deprecated in favor of opDispatch?
I personly need opDot, to customize member access ; not (only) method call. Denis
I'm pretty sure that you can use the getter/setter syntax with opDispatch, anything else is a bug. -- /Jacob Carlborg
Feb 17 2011
parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Jacob Carlborg <doob me.com> wrote:

 I'm pretty sure that you can use the getter/setter syntax with  
 opDispatch, anything else is a bug.
You can only use one of the two, and yes, the bug is already filed. -- Simen
Feb 17 2011