Thread overview
[Issue 2954] [tdpl] Appalling bug in associative arrays (D2 only)
Mar 19, 2014
Denis Shelomovskij
[Issue 2954] [tdpl] Allow to set associative array key value only using expression AA key type is constructable from
Mar 30, 2014
Denis Shelomovskij
March 19, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=2954


Denis Shelomovskij <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|patch                       |
             Status|RESOLVED                    |REOPENED
                 CC|                            |verylonglogin.reg@gmail.com
           Platform|x86                         |All
            Version|2.020                       |D2
         Resolution|FIXED                       |


--- Comment #8 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2014-03-19 15:38:05 MSK ---
Why is it marked as fixed?

If we are talking about original testcase, just replace `hash[a]` with `const ca = a; hash[ca]` and the program will work as in description. I see no fundamental difference here.

Currently implemented "fix": the compiler checks whether a key as an array and, if it is, checks whether its elements are mutable, if mutable, it complains "...can only be assigned values with immutable keys" (note even the error message is incorrect, not-mutable check and `immutable` in error).

IMO, the issue is associative arrays accept non-`immutable` keys and those keys can later be changed. E.g. keys of pointers, classes, associative arrays, and structs/unions with mutable indirection.

The whole issue is terrible and current inconsistent compiler behaviour with incorrect error message make situation even worse. The only visible solution is to disallow any associative array element set except with immutable key.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=2954



--- Comment #9 from Andrei Alexandrescu <andrei@erdani.com> 2014-03-19 08:51:30 PDT ---
Thanks, indeed it wasn't fixed. Current test code:

import std.stdio;

void main() {
    uint[string] hash;
    char[] a = "abc".dup;
    const ca = a;
    hash[ca] = 42;
    a[0] = 'A';
    writeln(hash.keys);
}

Accessing lvalues in a hash table must be done with a type assignable to the key type. Rvalue lookup may be done with types only comparable t the key type.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 30, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=2954


Denis Shelomovskij <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[tdpl] Appalling bug in     |[tdpl] Allow to set
                   |associative arrays (D2      |associative array key value
                   |only)                       |only using expression AA
                   |                            |key type is constructable
                   |                            |from


--- Comment #10 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2014-03-30 13:16:18 MSK ---
(In reply to comment #9)
> ...
> Accessing lvalues in a hash table must be done with a type assignable to the
> key type. Rvalue lookup may be done with types only comparable t the key type.

What does it mean "Accessing lvalues" and "Rvalue lookup"? It sounds like a meaningless terminology mix for me.

Anyway ability to set `V[K]` AA key using `expr` should compile iff `K x = expr` compiles i.e. `K` is constructable using `expr`. As for getting AA keys we have a complete mess too so I filed Issue 12492.

Also I changed this issue title to be precise.

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