[Issue 1560] Skip switch warning for complete enum set

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 10 16:32:54 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1560





------- Comment #3 from smjg at iname.com  2007-10-10 18:32 -------
(In reply to comment #2)
> I hadn't considered an enum instance containing an invalid value, though to my
> knowledge you have to intentionally do that with a cast.

My point is that it isn't necessarily invalid.  And you don't need a cast.  You
can combine enum values with arithmetic or bitwise operations, for example. 
Hence my mention of bit flags.

> Ignoring the issue of default, it would be still helpful to know at compile
> time if all enum cases are handled, but perhaps not in all cases.  How could
> this be checked cleanly?

I don't think there's any way we can be sure of considering all cases.  But a
possibility is to have a notation such as "switch enum (t)", such that it would
be a compile-time error not to consider all named values of the enum (whether
individually or with a default).  This would be a form of syntactic salt
similar to the override attribute.

> A similar case is when maintaining a parallel array:
> 
> char[][] name = [T.RED : "red", T.BLUE : "blue"];
> 
> How can we determine that GREEN is missing at compile time?

It used to be specified that an array must be initialised completely or not at
all.  See issue 508.  But this was never implemented.  Still, to work in this
instance, either the array's length would have to be explicitly given as T.max
+ 1, or it would miss a missing index at the end.


-- 



More information about the Digitalmars-d-bugs mailing list