On Friday, 4 January 2013 at 20:40:39 UTC, Walter Bright wrote:
On 1/4/2013 9:48 AM, Max Samukha wrote:
It looks we simply cannot modify existing declarations with UDAs.

@(attr) alias foo = bar; // @(attr) is ignored.

alias provides a way to provide an alternate name for a symbol.

I know what the intended semantics of alias is. But the reality is slightly different. See below.

It wouldn't be an alternate name if it had different attributes. Trying to make such work would have serious semantic consequences.

Hence, no, you cannot use alias to modify the attributes.

You can:

public struct S
{
}

private alias S S2; // visibility attribute is changed.

Type modifiers:

alias const(S) S2; // mutability attribute is changed.

I am not saying that UDAs should be designed so that they could modify the aliased "symbols" (that would be a fatality) - just noting that alias is already NOT a plain alternative name.

Reply via email to