const(Object)ref is here!
Michel Fortin
michel.fortin at michelf.com
Mon Dec 6 12:01:25 PST 2010
On 2010-12-06 14:46:51 -0500, spir <denis.spir at gmail.com> said:
> On Mon, 6 Dec 2010 13:44:41 -0500
> Michel Fortin <michel.fortin at michelf.com> wrote:
>
>> Since we're speaking of the optional use of 'ref', here's a little quiz:
>>
>> alias Object A;
>> alias Object ref B;
>>
>> A ref a;
>> B ref b;
>>
>> What happens here? Should there be an error somewhere? Where? Also,
>> what happens if we apply different modifiers at different places?
>
> As I understand the (non-)semantics of 'ref', there should be no error. Thi
> s code should considered by the compiler as equivalent to:
> Object a;
> Object b;
And that's what my patch does. It only gets confusing when you add modifiers:
alias const(Object)ref A;
alias const(Object ref) B;
alias const(Object) C;
A ref a;
B ref b;
C ref c;
With my patch, variables 'a', 'b', and 'c' are all of the same type:
"const(Object)ref", the later 'ref' changing the constness of the
reference specified in the 'B' alias.
Note that while this behaviour is allowed with an alias, it is *not*
allowed directly, so you can't write this for instance:
const(Object ref) ref d;
That's an error.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list