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

--- Comment #0 from 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 : #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:

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

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to