Bug 22586 – 'immutable field `xs` initialized multiple times' triggered by 'foreach' in constructor

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-12-12T03:02:48Z
Last change time
2024-12-13T19:19:47Z
Assigned to
No Owner
Creator
andy-hanson
Moved to GitHub: dmd#20021 →

Comments

Comment #0 by andy-hanson — 2021-12-12T03:02:48Z
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.
Comment #1 by robert.schadek — 2024-12-13T19:19:47Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20021 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB