Bug 22244 – Key tail immutability should allow hashmap to be impl converted from immutable to mutable

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-08-27T09:03:18Z
Last change time
2024-12-13T19:18:11Z
Keywords
industry
Assigned to
No Owner
Creator
FeepingCreature
Moved to GitHub: dmd#19976 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19976 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB