Custom attributes (again)

Timon Gehr timon.gehr at gmx.ch
Fri Apr 6 03:49:41 PDT 2012


On 04/06/2012 12:23 PM, Walter Bright wrote:
> On 4/6/2012 2:54 AM, Timon Gehr wrote:
>> Should add additional information to the type Foo. I don't see any
>> issues with
>> it, and not supporting it would be very strange.
>
> How would:
>
> @attr(foo) int x;
> int y;
>
> work? Are x and y the same type or not?

Yes, they are.

(But a future extension might leave this choice up to 'foo')

> Now, consider:
>
> auto c = b ? x : y;
>
> What type does c have? int or @attr(foo)int ? And that's really just the
> beginning. How about:
>
> struct S(T) {
> T t;
> }
>
> Instantiate it with S!int and S!(@attr(foo)int). Are those the same
> instantiation, or different? If the same, does S.t have the attribute or
> not?

There is no such thing as an @attr(foo) int, because @attr is not a type 
constructor.

>
> And, whatever you choose for the semantics, what is the sensible,
> intuitive rule for it?

Custom attributes apply to the symbol declaration. Because any symbol is 
declared just once, there is never any ambiguity. There is no conceptual 
gap between

@attr(foo) int x;

and

@attr(bar) struct S{...}

Obviously @attr(bar) changes S, but there is only one declaration of S.


More information about the Digitalmars-d mailing list