October 15, 2012 Re: Feature request: enum init shouldn't create a new enumeration | ||||
---|---|---|---|---|
| ||||
Posted in reply to 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.min;
while (me <= MyEnum.max)
{
// do something
++me;
}
final switch (me) // this should throw
{
case MyEnum.first: break;
case MyEnum.second: break;
case MyEnum.third: break;
}
Instead, currently this code runs just fine, none of the switch cases are taken. So, this bug might manifest itself very far from where it actually should have been throwing: on that final switch expression. Thus hunting this bug down could be tedious.
|
October 17, 2012 Re: Feature request: enum init shouldn't create a new enumeration | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tommi | https://github.com/D-Programming-Language/dmd/pull/673 "Tommi" <tommitissari@hotmail.com> wrote in message news:ozvdphftlwxkeumrnvoq@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: > > 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.min; > > while (me <= MyEnum.max) > { > // do something > ++me; > } > > final switch (me) // this should throw > { > case MyEnum.first: break; > case MyEnum.second: break; > case MyEnum.third: break; > } > > Instead, currently this code runs just fine, none of the switch cases are taken. So, this bug might manifest itself very far from where it actually should have been throwing: on that final switch expression. Thus hunting this bug down could be tedious. |
Copyright © 1999-2021 by the D Language Foundation