On Mon, 06 Dec 2010 15:01:25 -0500, Michel Fortin
<[email protected]> wrote:
On 2010-12-06 14:46:51 -0500, spir <[email protected]> said:
On Mon, 6 Dec 2010 13:44:41 -0500
Michel Fortin <[email protected]> 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.
I don't know if that's good. Redundancy is OK as long as it is
consistent. If Object ref is treated as Object everywhere it is used,
that helps to be able to explain how it works.
Similarly Object ref ref should probably reduce to Object.
We really need to ensure that all types using this notation are reduced to
their canonical types internally. Otherwise, strange results would occur.
-Steve