November 23, 2020
https://issues.dlang.org/show_bug.cgi?id=21418

          Issue ID: 21418
           Summary: Cannot use ref while iterating an immutable array in
                    ctor
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: temtaime@gmail.com

class C {
    this() {
        arr = [];
        foreach(ref a; arr) {} // Error: immutable field `arr` initialized
multiple times
    }

    void foo() {
        foreach(ref a; arr) {} // no error
    }

    immutable int[] arr;
}

foreach in ctor should compile fine like it does in foo.

--