Bug 22915 – Errors for invalid foreach aggregates should print the type

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-03-23T17:07:59Z
Last change time
2022-03-24T02:06:30Z
Keywords
pull
Assigned to
No Owner
Creator
moonlightsentinel

Comments

Comment #0 by moonlightsentinel — 2022-03-23T17:07:59Z
The error message for `foreach` over unusupported types print a rather unhelpful error message that only lists (parts of) the expression. But it isn't always obvious, why the expression doesn't yield an iterable value, e.g.: struct S { int opApply(scope int delegate(const int) dg); } S* someFunc(); void foo() { foreach (const i; someFunc()) // Pointer to S, needs dereference { // ... } }
Comment #1 by dlang-bot — 2022-03-23T17:26:59Z
@MoonlightSentinel created dlang/dmd pull request #13877 "Fix 22915 - Print the type of invalid foreach aggregates" fixing this issue: - Fix 22915 - Print the type of invalid foreach aggregates Mentioning the type alongside the expressions is helpful when the error isn't obvious, e.g. when the code didn't derefence a pointer. https://github.com/dlang/dmd/pull/13877
Comment #2 by dlang-bot — 2022-03-24T02:06:30Z
dlang/dmd pull request #13877 "Fix 22915 - Print the type of invalid foreach aggregates" was merged into master: - 979cdf592005473c7fbfe3b2b10925066fd3ffd7 by MoonlightSentinel: Fix 22915 - Print the type of invalid foreach aggregates Mentioning the type alongside the expressions is helpful when the error isn't obvious, e.g. when the code didn't derefence a pointer. https://github.com/dlang/dmd/pull/13877