bug in foreach continue

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 17 04:30:48 PDT 2017


On Friday, March 17, 2017 01:55:19 Hussien via Digitalmars-d-learn wrote:
> On Friday, 17 March 2017 at 01:41:47 UTC, Adam D. Ruppe wrote:
> > On Friday, 17 March 2017 at 01:34:52 UTC, Hussien wrote:
> >> Seems like continue needs to be static aware.
> >
> > That's not a bug, pragma is triggered when the code is
> > *compiled*, not when it is run. The code is compiled, even if
> > it is skipped over by a continue.
>
> My point is, that it shouldnt! a static if should have a static
> continue in some way. It is confusing to be thinking in terms of
> the compile time code and (static if) and use a ambiguous
> statement(continue) and it not be compile time.
>
> Either one needs a static version of continue or a warning when
> used inside a static if.
>
> As is, continue doesn't even apply to the static case, so it
> shouldn't be allowed. A static foreach with a dynamic continue is
> illogical yet no warning is emitted.

I tend to agree with this. If the foreach is static, and continue and break
are just going to be ignored, then they should just be illegal. Allowing
them is just going to confuse people. Now, making it so that they actually
work statically has some interesting possibilities, but that would fall
apart as soon as you have any constructs that would use continue or break
(e.g. a loop or switch statement) inside the static foreach, and it might
break code in rare cases. So, we're probably better off just making them
illegal. But having them be legal just seems disingenious, since they don't
do anything.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list