[Issue 13670] bug in assigning to dynamic array element

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Nov 1 18:19:50 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13670

Ketmar Dark <ketmar at ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar at ketmar.no-ip.org

--- Comment #2 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
(In reply to Jonathan M Davis from comment #1)
> So, essentially, you want to do something like
> 
> a[i] = i++
> 
> and have that be equivalent to
> 
> i++;
> a[i] = i;
nope. what i want for dynamic arrays is:
tmparr = &a;
tmpidx = i*a[0].sizeof;
i++;
tmparr.ptr[tmpidx] = i;

there is nothing that breaks evaluation order in case of dynamic arrays, and
with this change they will work exactly the same as static arrays.

or at least make compiler emit error on such assignments, so i don't have to
track if my variable is dynamic or static array manually.

> Regardless, I'd advise that you avoid any code where you mutate a variable
> in an expression and then use that same variable elsewhere in the
> expression.
as i wrote in NG, current behavior with dynamic arrays is plainly wrong. it
breaks "the least surprise" principle and requires programmer to manually track
variable types. not something i'd expect from "safe and powerful" language.

> In any case, AFAIK, your example does not currently count as a bug.
ah. so close it, please.

--


More information about the Digitalmars-d-bugs mailing list