Comment #0 by default_357-line — 2021-08-27T09:03:18Z
Consider this code:
struct Key
{
immutable(int)[] reference;
}
struct Foo
{
immutable(int)[Key] hashmap;
}
void main()
{
immutable Foo foo = Foo();
Foo bar = foo;
}
'Key' is clearly tail-immutable.
So 'Foo' is likewise tail-immutable, because the values of 'hashmap' cannot be changed, and the keys cannot be changed anyways - not by head, because key heads cannot be changed in a hashmap period (cannot be referenced, cannot be mutated), nor by tail, because Key is tail immutable.
There is a rule that tail immutable types can implicitly drop qualifier immutability, because they don't expose any further mutability on their referenced data that way.
Compare:
immutable string a;
string b = a;
So under the same logic, Foo should be able to convert to mutable.
(But it can't.)
Comment #1 by default_357-line — 2022-10-05T12:25:57Z
Simpler demonstration of the issue:
```
immutable int[string] foo;
immutable(int)[string] bar = foo;
```
This should work, because if we cast it:
```
immutable int[string] foo;
immutable(int)[string] bar = foo;
bar["foo"] = 5; // cannot modify `immutable` expression `bar["foo"]`
```
we see that the original `foo` is still protected. So the implconv should go through.
Comment #2 by robert.schadek — 2024-12-13T19:18:11Z