void main()
{
int i;
switch(i)
{
foreach(j; 0..10)
case j:{}
default: break;
}
}
DMD: Internal error: backend/symbol.c 1031
Comment #1 by b2.temp — 2016-09-21T22:08:11Z
The culprit is the local variable, as shown by this reduction
void main()
{
int i;
switch(i)
{
int j;
case j:{}
default: break;
}
}
which produces the same error.
Comment #2 by uplink.coder — 2016-09-21T22:20:20Z
It seems only to happen when the type is int.
if you change the type of j to uint it does produce the correct error in frontend
Comment #3 by uplink.coder — 2016-09-21T22:33:08Z
dmds source suggests that variables are allowed in switch-statements,
and that codegen should just generate an if-else-chain in this case.
I think allowing non-static cases is going to be a bugfest, down the road and we should think hard about this behavior.
(In reply to uplink.coder from comment #3)
>
> I think allowing non-static cases is going to be a bugfest, down the road
> and we should think hard about this behavior.
Declaration of a non-const variable in a switch body is now deprecated in master.
Comment #7 by uplink.coder — 2016-09-22T00:02:34Z
(In reply to Martin Krejcirik from comment #6)
> (In reply to uplink.coder from comment #3)
> >
> > I think allowing non-static cases is going to be a bugfest, down the road
> > and we should think hard about this behavior.
>
> Declaration of a non-const variable in a switch body is now deprecated in
> master.
That is not the issue.
The issue is weather they are compile-time or run-time values.
I believe having run-time values in there is not the best of choices.
Comment #8 by github-bugzilla — 2016-10-07T08:50:56Z