UDAs on enum members

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 17 10:01:10 PDT 2016


On Sunday, July 17, 2016 09:07:13 Ali Çehreli via Digitalmars-d wrote:
> To those who know the compiler internals, is there a reason why UDA are
> not applied to all turtles? (I guess the answer is not that simple. :) )

Mabye some of them are actually tortoises? ;)

D's features rarely seem to be implemented as "turtles all the way down" to
begin with. That's usually something that comes later after folks complain
about something that they think is inconsistent. And it's sometimes
disputable as to whether something counts as being "turtles all the way
down" or whether it would actually be a good idea to _not_ do "turtles all
the way down" (for instance, some of the way that attributes are applied
such that you're allowed to put them on all kinds of things where they don't
apply but don't get an error is arguably a case of "turtles all the way
down," but it's also quite problematic at least some of the time).

In this particular case, I have no idea whether it would be a good idea or
not, but it is a bit similar to applying UDAs to variables, which would be
rather odd (though per the OP, it sounds like it's legal to put them on
member variables; I don't have any experience with UDAs though, so I'm not
sure what their restrictions are exactly). And if you can put UDAs on enum
members the way that the OP is looking to do, that immediately poses the
question of whether something like

enum @MyUDA foo = "hello world";

should be legal, and if we do that, we're pretty much at the point that any
variable should be allowed to have a UDA, which seems pointless and
overcomplicated to me - particularly with regards to local variables. I
expect that if there's a good enough, practical argument to be made, then we
could end up with UDAs on enum members, but that argument is going to have
to be made such that Walter and Andrei are convinced, which may or may not
be easy. But anyone who feels strongly about this should consider putting
together a DIP.

- Jonathan M Davis




More information about the Digitalmars-d mailing list