digitalmars.D.bugs - [Issue 8737] New: Associative Array (AA) KeyType is not Unqual-able
- d-bugmail puremagic.com (65/65) Sep 29 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8737
- d-bugmail puremagic.com (24/31) Sep 29 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8737
- d-bugmail puremagic.com (11/11) Oct 04 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8737
- d-bugmail puremagic.com (11/11) Oct 05 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8737
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 --- Comment #0 from monarchdodra 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: -------
Sep 29 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8737 --- Comment #1 from monarchdodra gmail.com 2012-09-29 15:55:11 PDT --- (In reply to comment #0)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
http://d.puremagic.com/issues/show_bug.cgi?id=8737 --- Comment #2 from github-bugzilla puremagic.com 2012-10-04 11:56:29 PDT --- 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 Merge pull request #822 from monarchdodra/unqual 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
http://d.puremagic.com/issues/show_bug.cgi?id=8737 monarchdodra gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID --- Comment #3 from monarchdodra gmail.com 2012-10-05 15:39:43 PDT --- 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