Why D is annoying =P

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Oct 24 12:36:20 PDT 2012


On Wed, Oct 24, 2012 at 09:17:09PM +0200, Mehrdad wrote:
[...]
> Could someone explain what's going on? Thanks!
> 
> import std.stdio;
> struct S { int[int] aa; }
> void main()
> {
> 	writeln(  [1: 2]  ==   [1: 2] );  // true
> 	writeln(S([1: 2]) == S([1: 2]));  // false
> }
[...]

I don't know if there is any struct-specific problem here, but AA
comparison right now is horribly horribly broken (search on the bug
tracker for "AA" and you'll see a bunch of issues on that end). You're
incredibly lucky that two AA literals actually compared equal. In some
cases, not even that is guaranteed.

I've tried to clean up the AA code but it's a tangled messy ugly
labyrinth with fragile hacks sprinkled in, and didn't get to the point
where it's ready to commit. One major obstacle is that parts of it are
implemented in compiler hacks, and part of it is schizophrenically
duplicated in object_.d, not necessarily consistently, and it's just Not
Nice in general. That it works at all is reason enough to be thankful. I
don't expect things to be pretty once you start poking into the
intricacies of AA's, sad to say.


T

-- 
People tell me I'm stubborn, but I refuse to accept it!


More information about the Digitalmars-d mailing list