Wrong lowering for a[b][c]++

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Mar 22 07:35:06 PDT 2012


On Thu, Mar 22, 2012 at 03:26:00PM +0100, Andrej Mitrovic wrote:
> On 3/22/12, Jesse Phillips <jessekphillips+D at gmail.com> wrote:
> > double[int] a;
> > What is the result of your code on 'a' now? double.init is NAN.
> 
> Hmm this is interesting. With 2.058:
> 
> double[int] a;
> a[0]++;
> writeln(a[0]);  // prints 1
> 
> double b;
> b++;
> writeln(b);  // prints nan

This is because in aaA.d _aaGetX creates a new entry if one isn't found,
but because it has no direct access to value types (only has typeinfo),
it doesn't know what value .init has. It sets the value to binary zero
by default.

(This is one of the places where you *really* want the AA implementation
to be in object_.d, where it can actually say Value.init instead of
hacking it with binary zero, which is wrong in this case but pretty much
impossible to fix.)


T

-- 
If it tastes good, it's probably bad for you.


More information about the Digitalmars-d mailing list