Bug 20671 – T[] can't implicitly convert to immutable(T)[] even if T is de-facto immutable

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-03-13T10:13:35Z
Last change time
2024-12-13T19:07:38Z
Assigned to
No Owner
Creator
FeepingCreature
Moved to GitHub: dmd#19677 →

Comments

Comment #0 by default_357-line — 2020-03-13T10:13:35Z
Consider a struct S: struct S { immutable int i; } Even though it's nominally mutable, it contains no mutable fields. However, if we have a "mutable" array: S[] array = [S(5)]; We cannot convert this array to immutable(S)[] immutable(S)[] array2 = array; // errors Even though this is clearly safe, because S has no fields that could mutate or be mutated, whether you write `S` or `immutable(S)`. This combines with https://issues.dlang.org/show_bug.cgi?id=20670 to make immutable arrays effectively unusable as struct members.
Comment #1 by robert.schadek — 2024-12-13T19:07:38Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19677 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB