[Issue 13670] bug in assigning to dynamic array element

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Nov 28 20:44:34 PST 2014


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

--- Comment #8 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
the code is clearly meaningless in most cases. what compiler *should* do is at
least emit warning about possible side-effects here, but not silently hiding
that.

this is *built-in* type, i can't fix it by fixing my "dynamic array class". and
i don't want to remember if the array i used is static or not, if the function
changes it's length or not and so on. i want compiler to help me by emiting
warning about such dangerous assigns. compiler *knows* that this is dynamic
array, and it *knows* that the function is not marked as "pure", so it *must*
warn me. not trying to cheat me, not playing games "are you smart enough?" with
me, but help me to fix my code.

yet compiler says me nothing and hapily accepts this. ok, the program is not
segfaulting, but i prefer it to segfault instead of silently modifying a stale
array copy.

i was not expected such behavior with *built-in* types.

sure, compiler can't catch everything, but does this mean that it shouldn't try
to catch at least something?

i catched at least three such bugs in my code, and all of them due to dynamic
arrays that looking *exactly* as static arrays, so i wrote that code without
second thought: "if it looks the same, it probably works the same, and if i
wrong the compiler will tell me, right?" ah… wrong.

and then this was closed as "invalid", indicating that compiler will not stop
it's attempts to cheat me and hide my bugs.

i'm not expecting that our juniors will not reproduce this bug over and over
again, so "it's dangerous to go alone".

--


More information about the Digitalmars-d-bugs mailing list