Shared/const/immutable does not propagate to hash keys

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue Jun 14 13:11:01 PDT 2011


shared int[int] AA;
shared int[] arr;

void main()
{
    arr = AA.keys;
}

Error: cannot implicitly convert expression (AA.keys()) of type int[]
to shared(int[])

Workaround:

shared int[shared(int)] AA;
shared int[] arr;

void main()
{
    arr = AA.keys;
}

Shouldn't shared propagate to the entire type?
The same thing seems to happen with const and immutable:

    const int[const(int)] CONST = [1:1];
    auto arr1 = CONST.keys;
    writeln(typeid(arr1));  // const(int)[]

    const int[int] NOTCONST = [1:1];
    auto arr2 = NOTCONST.keys;
    writeln(typeid(arr2));  // int[]

But .values doesn't suffer from the issue:

import std.stdio;
shared (int[int]) AA;

void main()
{
    auto arr1 = AA.keys;
    auto arr2 = AA.values;
    writeln(typeid(arr1));  // writes int[]
    writeln(typeid(arr2));  // writes shared(int)[]
}


More information about the Digitalmars-d-learn mailing list