[Issue 20671] New: T[] can't implicitly convert to immutable(T)[] even if T is de-facto immutable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 13 10:13:35 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20671
Issue ID: 20671
Summary: T[] can't implicitly convert to immutable(T)[] even if
T is de-facto immutable
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: default_357-line at yahoo.de
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.
--
More information about the Digitalmars-d-bugs
mailing list