www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22244] New: Key tail immutability should allow hashmap to be

https://issues.dlang.org/show_bug.cgi?id=22244

          Issue ID: 22244
           Summary: Key tail immutability should allow hashmap to be impl
                    converted from immutable to mutable
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de

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.)

--
Aug 27