http://d.puremagic.com/issues/show_bug.cgi?id=8737

           Summary: Associative Array (AA) KeyType is not Unqual-able
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: monarchdo...@gmail.com


--- Comment #0 from monarchdo...@gmail.com 2012-09-29 15:42:26 PDT ---
There is an issue with AA's, where it is not possible to extract the exact
"mutable KeyType" of an AA. This is a built in protection for when iterating on
reference keys.

The problem is that it becomes impossible to create new keys, without knowing
the "real" type.

This was revealed in a bug in conv.to : #8705
http://d.puremagic.com/issues/show_bug.cgi?id=8705

Reduced test:

--------
import std.stdio;
import std.traits;
import std.conv;

void main()
{
    alias short[short[short]] S;
    alias int[int[int]] T;
    S value;
    T result;

    alias Unqual!(KeyType!T)   K2; // const(int)[int]
    alias Unqual!(ValueType!T) V2; // int

    foreach (k1, v1; value)
    {
        K2 k2 = to2!K2(k1); //request a cast to "const(int)[int]" !!!
        V2 v2 = to!V2(v1);
        result[k2] = v2;
    }
}

T to2(T, S)(S value) //T is const(int)[int]
{
    alias Unqual!(KeyType!T)   K2;
    alias Unqual!(ValueType!T) V2;
    Unqual!T result;

    foreach (k1, v1; value)
    {
        K2 k2 = to!K2(k1); //const(int)
        V2 v2 = to!V2(v1); //int
        result[k2] = v2; //Error: result[k2] isn't mutable (naturally)
    }
    return result;
}
--------
Here, the implementer of "foo" is unable to tranform his keys, because their
types are not mutable.

The real problem is that KeyType returned "const(int)[int]", is not really
const, but not mutable either. Because of this Unqual doesn't work.

Suggestion: The type returned by KeyType should be "full const", eg:
const(int[int]).

This would make it just as safe, but a user can still request an Unqual on the
type.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to