[Issue 2954] [tdpl] Appalling bug in associative arrays (D2 only)

2014-03-19 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=2954


Denis Shelomovskij verylonglogin@gmail.com changed:

   What|Removed |Added

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


--- Comment #8 from Denis Shelomovskij verylonglogin@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: ---


[Issue 2954] [tdpl] Appalling bug in associative arrays (D2 only)

2014-03-19 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=2954



--- Comment #9 from Andrei Alexandrescu and...@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: ---


[Issue 2954] [tdpl] Appalling bug in associative arrays (D2 only)

2010-12-06 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2954


Walter Bright bugzi...@digitalmars.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||FIXED


--- Comment #7 from Walter Bright bugzi...@digitalmars.com 2010-12-06 
12:21:48 PST ---
http://www.dsource.org/projects/dmd/changeset/789

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


[Issue 2954] [tdpl] Appalling bug in associative arrays (D2 only)

2010-11-19 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2954



--- Comment #5 from Don clugd...@yahoo.com.au 2010-11-19 06:36:06 PST ---
(In reply to comment #4)
 The fix still isn't right, as it fails at compile time on line 10.

It works for me. Hmm.
I think this might also be relying on the patch for bug 5218, which I still
have active in my local copy. Sorry about that -- it needs to be included as
well.

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


[Issue 2954] [tdpl] Appalling bug in associative arrays (D2 only)

2010-11-18 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2954



--- Comment #4 from Walter Bright bugzi...@digitalmars.com 2010-11-18 
20:48:37 PST ---
The fix still isn't right, as it fails at compile time on line 10.

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


[Issue 2954] [tdpl] Appalling bug in associative arrays (D2 only)

2010-11-16 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2954


Don clugd...@yahoo.com.au changed:

   What|Removed |Added

   Keywords||patch
 CC||clugd...@yahoo.com.au


--- Comment #3 from Don clugd...@yahoo.com.au 2010-11-16 01:10:11 PST ---
The fix for bug 2684 was incorrect; it was too general. We can't skip the
implicit conversion in all cases where the arrays are equality comparable.

For example, this code:

char[char[3]] ac;
dchar[3] d = abcd;
ac[d] = 'w';
gives a poor error message:
bug.d(6): Error: array equality comparison type mismatch, dchar[3u] vs char
[3u]
instead of cannot implicitly convert

PATCH: 
(1) Add this function to cast.c

/***
 * See if both types are arrays that can be compared
 * for equality without any casting. Return !=0 if so.
 * This is to enable comparing things like an immutable
 * array with a mutable one.
 */
int arrayTypeCompatibleWithoutCasting(Loc loc, Type *t1, Type *t2)
{
t1 = t1-toBasetype();
t2 = t2-toBasetype();

if ((t1-ty == Tarray || t1-ty == Tsarray || t1-ty == Tpointer) 
t2-ty == t1-ty)
{
if (t1-nextOf()-implicitConvTo(t2-nextOf()) = MATCHconst ||
t2-nextOf()-implicitConvTo(t1-nextOf()) = MATCHconst)
return 1;
}
return 0;
}

(2) expression.c line 8580

case Taarray:
{   TypeAArray *taa = (TypeAArray *)t1;
+/* We can skip the implicit conversion if they differ only by
+ * constness (Bugzilla 2684, see also bug 2954b)
+ */
+if (!arrayTypeCompatibleWithoutCasting(e2-loc, e2-type,
taa-index) )
-if (!arrayTypeCompatible(e2-loc, e2-type, taa-index))
{
e2 = e2-implicitCastTo(sc, taa-index);// type
checking
}
type = taa-next;

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


[Issue 2954] [tdpl] Appalling bug in associative arrays (D2 only)

2010-11-11 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2954


Walter Bright bugzi...@digitalmars.com changed:

   What|Removed |Added

 CC||bugzi...@digitalmars.com


--- Comment #2 from Walter Bright bugzi...@digitalmars.com 2010-11-11 
17:56:01 PST ---
http://www.dsource.org/projects/dmd/changeset/749

This fixes Andrei's bug, but Don's is a different bug.

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