Help needed: immutable struct is a type modifier, and that's wrong and broken
FeepingCreature
feepingcreature at gmail.com
Fri Mar 13 14:17:45 UTC 2020
On Friday, 13 March 2020 at 13:25:52 UTC, Jacob Carlborg wrote:
> import std;
>
> immutable struct S { }
>
> void main()
> {
> Unqual!S s;
> Unqual!S s2;
>
> pragma(msg, typeof(s)); // will print S
> s = s2;
> }
>
> The above code will compile, but if you add a member to S, it
> fails:
>
> Error: cannot modify struct instance `s` of type `S` because it
> contains `const` or `immutable` members
>
> Even though it looks like it's possible to strip of the
> immutable qualifier it will actually not work in practice. If
> you don't have any members, it doesn't really matter. If you do
> have members, it will not compile.
>
> --
> /Jacob Carlborg
Okay, so you're saying there's an immutable modifier on S, but it
doesn't do anything because all the fields are immutable too?
So the actual problem would be
https://issues.dlang.org/show_bug.cgi?id=20671 , where the
immutable-stripped type is just different enough to prevent array
conversion.
In that case, isn't the solution just to ditch the extraneous
implicit immutable() entirely? I mean, either it should always be
on S or it should never be on S.
More information about the Digitalmars-d
mailing list