www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8737] New: Associative Array (AA) KeyType is not Unqual-able

reply d-bugmail puremagic.com writes:
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: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com



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.


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: -------
Sep 29 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8737





 Here, the implementer of "foo" is unable to tranform his keys, because their
 types are not mutable.
I meant "to"
 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]).
No, wait that is bad advice. Recommend changing "Unqual" actually; -------- template Unqual(T) if(!isAssociativeArray!T) //New condition { //As it was } //New overload template Unqual(T) if(isAssociativeArray!T) { alias KeyType!T K; alias Unqual!(ValueType!T) V; alias V[K] Unqual; } -------- I'll do this tommorrow, unless I get some objections? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8737




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/dabb0343ba173912c8d15ed8cffeedf20420b7f0
fix issue 8737 Unqual for AA

https://github.com/D-Programming-Language/phobos/commit/4bd36016e2385292a86d1acc629d04e939fbf03d


fix issue 8737 Unqual for AA

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 04 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8737


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



Invalid per https://github.com/D-Programming-Language/phobos/pull/822 .

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