Users may attempt to do type inference in foreach statements in the following way:
foreach (auto e; foo) { }
However, this causes the following compilation error:
>Error: basic type expected, not auto
This can be fairly misleading as an inexperienced programmer may assume that type inference is not possible inside foreach statements, as the compiler says it expects a basic type (when it syntactically actually doesn't).
As per http://forum.dlang.org/post/[email protected] I suggest adding a special case if the unexpected token inside a foreach statement's declaration is "auto", pointing out that "auto" is neither needed nor allowed in this context to get type inference.
Comment #1 by dlang-bot — 2023-01-21T12:32:58Z
@dkorpel created dlang/dmd pull request #14839 "Fix 15368 - improve error message when using auto in foreach" fixing this issue:
- fix 15368 - improve error message when using auto in foreach
https://github.com/dlang/dmd/pull/14839
Comment #2 by dlang-bot — 2023-01-23T08:38:35Z
dlang/dmd pull request #14839 "Fix 15368 - improve error message when using auto in foreach" was merged into stable:
- e7c2729806c1e7328c736af1177b322942717f17 by Dennis Korpel:
fix 15368 - improve error message when using auto in foreach
https://github.com/dlang/dmd/pull/14839
Comment #3 by dlang-bot — 2023-02-02T07:33:23Z
dlang/dmd pull request #14857 "merge stable" was merged into master:
- 3683d2384a4eecdc2f816177a04f3a52032f8f79 by Dennis:
fix 15368 - improve error message when using auto in foreach (#14839)
https://github.com/dlang/dmd/pull/14857