Possible @property compromise

Zach the Mystic reachBUTMINUSTHISzach at gOOGLYmail.com
Tue Jan 29 17:20:37 PST 2013


On Wednesday, 30 January 2013 at 01:09:12 UTC, H. S. Teoh wrote:
> As for using struct to implement @property, I like the idea, 
> but it does
> raise tricky issues about how struct methods reference the 
> parent
> lexical scope. I don't think it's as simple as just rewriting 
> 'this' to
> point to the outer scope instead, because it breaks language
> expectations that 'this' should refer to the 
> immediately-containing
> struct/class. There's bound to be corner cases that will break 
> because
> of this. Consider, for example, what happens if the inner 
> struct's
> methods need to call opAssign of the parent struct for whatever 
> reason.

outer.this
outer.opAssign

> There's also the consideration of what happens if you take the 
> address
> of the 'pseudo' variable: the inner struct would then be 
> effectively
> dissociated from the parent struct, and you'll need that hidden 
> context
> pointer (along with its gotchas) in order to have things still 
> work as
> before.

Compiler detects a struct which holds no data of its own and 
disallows taking its address.


More information about the Digitalmars-d mailing list