#1450 Syntactic sugar gotcha

vkuzkokov Thu 17 Mar 2011

As most of you already know

a[i] = v

is actually

a.set(i,v)

I should also note that this transformation happens very early in compiler pipeline. Now think of

t := a[i] = v

set returns this, so t will be assigned to a, not the stored value, as some might expect.

DanielFath Fri 18 Mar 2011

Don't know. Seems logical to me (if you read the docs). What did you expect to return? Bool or the element that was added?

vkuzkokov Fri 18 Mar 2011

I'd expect to get stored result as in C/Java/whatever, so that:

x = expr = v

is basically the same as

expr = v; x = expr

Login or Signup to reply.