Bug 13577 – More informative error message for refused immutable foreach loop

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-10-06T13:22:18Z
Last change time
2023-03-07T16:38:03Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-10-06T13:22:18Z
This is a low-priority diagnostic enhancement request. I'd like a more informative error message for situations like: import std.algorithm: enumerate; void main() { auto arr = [[1]]; foreach (immutable i, const x; arr.enumerate) {} // OK foreach (immutable i, immutable x; arr.enumerate) {} // Error } dmd 2.067alpha gives: temp.d(5,5): Error: cannot infer argument types I'd like an error message that explains that x can't be immutable. See this other example: void main() { auto arr = [[1]]; immutable a0 = arr[0]; } It gives an informative message: test.d(3): Error: cannot implicitly convert expression (arr[0]) of type int[] to immutable(int[])
Comment #1 by dlang-bot — 2023-02-27T12:47:39Z
@RazvanN7 created dlang/dmd pull request #14924 "Fix Issue 13577 - More informative error message for refused immutable foreach loop" fixing this issue: - Fix Issue 13577 - More informative error message for refused immutable foreach loop https://github.com/dlang/dmd/pull/14924
Comment #2 by dlang-bot — 2023-03-07T16:38:03Z
dlang/dmd pull request #14924 "Fix Issue 13577 - More informative error message for refused immutable foreach loop" was merged into master: - 0fae5775aa72fe131e168011d6787ac3874b10ad by RazvanN7: Fix Issue 13577 - More informative error message for refused immutable foreach loop https://github.com/dlang/dmd/pull/14924