[Issue 16672] Deprecate "block only" delegate syntax
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Nov 10 04:17:58 PST 2016
https://issues.dlang.org/show_bug.cgi?id=16672
Nick Treleaven <nick at geany.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nick at geany.org
--- Comment #1 from Nick Treleaven <nick at geany.org> ---
Link to most recent question on the forum:
http://forum.dlang.org/post/pcbqcrujjewmdptuggsy@forum.dlang.org
Andrei uncovered this gem:
int j;
for({j=2; int d = 3; } j+d<7; {j++; d++;}) {
}
http://forum.dlang.org/thread/nud21i$o29$1@digitalmars.com
As he explains, the Initialize part of `for` grammar specially allows
BlockStatement, but the Increment part is just an expression. So {j++; d++;} is
an expression, *not* a BlockStatement, which parses as a nullary delegate,
which is never called! Hence infinite loop.
Andrei also mentions an alternative fix:
> Another possibility is to disallow an ExpressionStatement that
> consists solely of a lambda. There is precedent for that, e.g.
> the statement "1 + 1;" is disallowed. -- Andrei
--
More information about the Digitalmars-d-bugs
mailing list