[Issue 11051] Unmatched case in a final switch should throw in both release and non-release mode
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Aug 19 02:39:29 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=11051
--- Comment #7 from Don <clugdbug at yahoo.com.au> ---
This is an error which should be caught by the type system at compile time, but
the type system is broken for enums.
The problem is that the 'enum' keyword can mean either 'genuine enumeration' or
'collection of named constants with some unspecified relationship between
them'.
A 'genuine enumeration' has an implicit contract that it only contains valid
values. And 'final switch' relies on that contract. This is broken, because the
type system doesn't make that promise. The run-time assert that it's a valid
value is really just a hack.
Only a 'genuine enumeration' makes sense in a final switch. And arithmetic and
logical operations don't make sense on genuine enumerations.
Interestingly, a whole-program lint tool could identify all enums which appear
inside a 'final switch', and disallow all arithmetic on them. <g> Of course
that's completely backwards. The semantics of the enum _should_ be deducable
from the declaration of the enum.
I see no reason to regard violations of that implicit contract as somehow more
important than other contracts. *Any* contract violation will result in
incorrect runtime behaviour. The bottom line is that -release is a very
dangerous flag. I don't think we should promote a false sense of security about
it.
--
More information about the Digitalmars-d-bugs
mailing list