On Tue, 25 Feb 2014 14:33:05 -0500, Walter Bright
<newshou...@digitalmars.com> wrote:
On 2/25/2014 2:28 AM, Daniel Murphy wrote:
Walter + Andrei did it, and it was completely intentional, and it was
known that
it would break code.
https://github.com/D-Programming-Language/dmd/pull/3054
It was intended to only break code that was already broken (would fail
at runtime). It appears that this turned out to not be entirely true.
I just wrote this and compiled on 2.064:
import std.stdio;
struct S
{
int x;
int y;
bool opEquals(ref const(S) other) const { return other.x == x;}
}
void main()
{
int[S] aa;
aa[S(1, 2)] = 5;
aa[S(1, 3)] = 6;
writeln(aa);
}
Output:
[S(1, 2):5, S(1, 3):6]
Now, clearly this is not correct, and should be flagged by the compiler,
or fixed in the runtime.
I suggest this path:
1. Switch AA to using the 'equals' function
2. Do not allow keys that provide opCmp function but not opEquals (these
will not work correctly)
This will provide a sane implementation and not break existing code when
the default opEquals and opCmp are used (both will act the same as far as
AAs are concerned).
-Steve