Bug 22227 – `if (scope f = x())` and `while (scope f = x())` do not parse
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-20T11:37:50Z
Last change time
2021-08-21T12:29:32Z
Keywords
pull
Assigned to
No Owner
Creator
Mathias LANG
Comments
Comment #0 by pro.mathias.lang — 2021-08-20T11:37:50Z
```
void main ()
{
if (scope foo = bar())
assert(0);
}
int* bar () { return null; }
```
```
void main ()
{
while (scope foo = bar())
assert(0);
}
int* bar () { return null; }
```
Those two snippets should compile.
Comment #1 by per.nordlow — 2021-08-20T12:27:47Z
Looking at how
```
for (scope i = 0; i < 1; ++i) {}
```
is parsed might give guidance.
Comment #2 by dkorpel — 2021-08-21T10:57:30Z
The spec doesn't allow storage classes in IfCondition, only `auto` or a type. __gshared and static also don't parse inside if-statements and while-statements. Marking as an enhancement instead of rejects-valid.
Comment #3 by dlang-bot — 2021-08-21T10:57:52Z
@dkorpel created dlang/dlang.org pull request #3091 "Update grammar for issue 22227" mentioning this issue:
- update grammar for issue 22227
https://github.com/dlang/dlang.org/pull/3091
Comment #4 by dlang-bot — 2021-08-21T10:58:07Z
@dkorpel created dlang/dmd pull request #12999 "Fix issue 22227 - `if (scope f = x())` and `while (scope f = x())` do not parse" fixing this issue:
- fix issue 22227 - `if (scope f = x())` and `while (scope f = x())` do not parse
https://github.com/dlang/dmd/pull/12999
Comment #5 by dlang-bot — 2021-08-21T12:28:52Z
dlang/dmd pull request #12999 "Fix issue 22227 - `if (scope f = x())` and `while (scope f = x())` do not parse" was merged into master:
- 368d408de2fcd8165fb70085eb2afa380a12f565 by dkorpel:
fix issue 22227 - `if (scope f = x())` and `while (scope f = x())` do not parse
https://github.com/dlang/dmd/pull/12999
Comment #6 by dlang-bot — 2021-08-21T12:29:32Z
dlang/dlang.org pull request #3091 "Update grammar for issue 22227" was merged into master:
- 24becf5fa95e9c606e3ba1b0a13d171f721a292c by dkorpel:
update grammar for issue 22227
https://github.com/dlang/dlang.org/pull/3091