https://issues.dlang.org/show_bug.cgi?id=22586
Issue ID: 22586
Summary: 'immutable field `xs` initialized multiple times'
triggered by 'foreach' in constructor
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
This file causes a compile error:
```
struct S {
immutable int[] xs;
this(immutable int[] xs_) {
xs = xs_;
foreach (ref immutable int x; xs) {}
}
}
```
The error is:
```
$ dmd a.d
a.d(5): Error: immutable field `xs` initialized multiple times
a.d(4): Previous initialization is here.
```
This isn't right because iterating over `xs` should count as reading it, not as
initializing it.
Tested with dmd v2.098.0.
--