[Issue 13577] New: More informative error message for refused immutable foreach loop

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Oct 6 06:22:18 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13577

          Issue ID: 13577
           Summary: More informative error message for refused immutable
                    foreach loop
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: bearophile_hugs at eml.cc

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[])

--


More information about the Digitalmars-d-bugs mailing list