On Thursday, 21 November 2013 at 08:05:03 UTC, Michal Minich
wrote:
On Thursday, 21 November 2013 at 07:42:48 UTC, Craig Dillabaugh
wrote:
I should also mention, this post likely better belongs in:
digitalmars.D.learn
I don't entirely think so. I think the OP is arguing that D
should be able to identify symbol as specific enum's field when
used:
- in place of function argument when the fn parameters is of
enum type
- and when comparing for equality with variable of enum type.
ie. the lookup of the symbol should be first inside the enum,
and the continue normally.
There was plan long long time ago to implement it, but I don't
remember for which reason it was not.
In order to consider this again for implementation I think
proper DIP should be written where complete semantics of this
should be described. For one I don't know how it should be have
if you would have variable of the same name as enum field i.e:
enum State { on, off }
auto State s;
auto on = 1;
if (on == on) ?
And I think it would be especially confusing when enum which is
function parameters has the same field name as local variable
on call site:
void change (State s) {}
void main () { State on = State.off, change (on) }
Michal,
Well thank you for a sane reply! I've been with D since about
2006, and I prefer to not make a complete fool of myself.
I have to admit that the question was asked in anger. I was
working on some old code, and saw this large bare enum, so I gave
it a qualifier. It then took me about six hours to stubbornly go
through the rest of the code to add the qualifier - aargh!
Yes, I agree that the circumstances under which the inference
could be made may be limited, but in a function where a single
argument is an enum name it's really surprising that it is not
implemented.
Could 'with' be extended to cover enum names do you think? Also a
supplementary question - does auto lock out some things like
this, are there other examples?