UDA strange behavior

David d at dav1d.de
Sun Jun 9 03:19:39 PDT 2013


Am 09.06.2013 11:15, schrieb Temtaime:
> @(3) int a;
> enum tp = __traits(getAttributes, a);
>                
> enum b = tp[0];
> writeln(b);
> 
> Compiler doesn't accept enum b = tp[0] and says to me:
> Error: variable _tp_field_0 cannot be read at compile time
> 
> Why? And writeln(tp[0]) works as expected.

It works like that:
http://dpaste.dzfl.pl/809de989

@(3) int a;
enum tp = [__traits(getAttributes, a)];
enum b = tp[0];
pragma(msg, b);


The exact reason why you have to expand the tuple into an array, I don't
know, or can't remember ;)


More information about the Digitalmars-d-learn mailing list