Re: Feature request: enum init shouldn't create a new enumeration

2012-10-17 Thread Daniel Murphy
https://github.com/D-Programming-Language/dmd/pull/673 "Tommi" wrote in message news:ozvdphftlwxkeumrn...@forum.dlang.org... > On Monday, 15 October 2012 at 08:25:18 UTC, Tommi wrote: >> in reality, it's very easy to write a bug that makes an enum variable >> have an invalid value. E.g: > > Wri

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-15 Thread Tommi
On Monday, 15 October 2012 at 08:25:18 UTC, Tommi wrote: in reality, it's very easy to write a bug that makes an enum variable have an invalid value. E.g: Writing that bug wasn't as easy as I thought though. Here's the code with a bug: enum MyEnum { first, second, third } auto me = MyEnum.m

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-15 Thread Tommi
On Sunday, 14 October 2012 at 19:40:17 UTC, Nick Sabalausky wrote: Yes, but it still has to be taken into account in things like "final switch". You can't just pretend that nothing will ever have that value, because by making it the init value, you've *made* it an actual possible value, one that

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-14 Thread Nick Sabalausky
On Sun, 14 Oct 2012 09:16:28 +0200 "Tommi" wrote: > On Sunday, 14 October 2012 at 06:51:48 UTC, Jonathan M Davis > wrote: > > And honestly, declaring a specific init value for an enum is a > > stupid idea. > > I think that declaring a specific *valid* init value for an enum > has no purpose.

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-14 Thread Tommi
On Sunday, 14 October 2012 at 06:51:48 UTC, Jonathan M Davis wrote: And honestly, declaring a specific init value for an enum is a stupid idea. I think that declaring a specific *valid* init value for an enum has no purpose. But declaring a specific *invalid* init value, to which the enum ini

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-13 Thread Jonathan M Davis
On Sunday, October 14, 2012 08:20:40 Tommi wrote: > There's a bug in that code, because MyEnum default-initializes to > an invalid value. It's effectively the same as this following > code, where the programmer has failed to initialize MyEnum > variable with a valid value: Valid or not, MyEnum.ini

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-13 Thread Tommi
On Saturday, 13 October 2012 at 20:25:56 UTC, Jonathan M Davis wrote: MyEnum me; final switch (me) // no init case necessary nor allowed { case MyEnum.first: break; case MyEnum.second: break; } } Think about that for a moment. What happens when that final switc

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-13 Thread Jonathan M Davis
On Saturday, October 13, 2012 17:39:23 Tommi wrote: > I'd like to be able to specify a default value for a named enum, > E.init, without creating a new enumeration. There are three > reasons: > 1) Default initializing enum variables to an "invalid" value > 2) Being able to use 'final switch' withou

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-13 Thread Ali Çehreli
On 10/13/2012 11:01 AM, bearophile wrote: denizzzka: Why in case its need to write name of the enum? Because D enums have a very simple design. But with() helps. For me, that is the only benefit of 'with': final switch (me) with (MyEnum) { case first: break; case second: b

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-13 Thread bearophile
denizzzka: Why in case its need to write name of the enum? Because D enums have a very simple design. But with() helps. Bye, bearophile

Re: Feature request: enum init shouldn't create a new enumeration

2012-10-13 Thread denizzzka
On Saturday, 13 October 2012 at 15:39:24 UTC, Tommi wrote: enum MyEnum { init = -123, first = 0, second = 1 } void main() { static assert(MyEnum.min == -123); MyEnum me; final switch (me) { case MyEnum.first: break; case MyEnum.second: break; case MyEnu