bug in assigning to dynamic array element

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 1 07:54:31 PDT 2014


On Sat, 1 Nov 2014 14:44:54 +0000
Iain Buclaw via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> You can clearly see the 'list.length' though.  You can't possibly go
> off the assumption that if you grow the size of a dynamic array, it's
> area in memory won't be relocated.
i don't even want to know if that was dynamic or static array! why
should i remember that? isn't type checking is what compiler does for
us? ;-)

dynamic arrays either should not look like static arrays, or should
work as static arrays. it's ok for class/struct opAssign() to has some
side effects, but it's not ok for built-in things. compiler is
perfectly able to at least emit error there. or make that code work as
it should work by dereferencing .ptr before doing 'mov' and not before
calling `saveIt()`.

i don't even want to know about that '.ptr' thing after all. the sample
should either consistently not updating the array element, or
consistenly updating it, following the principle of the least surprise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141101/bc5e5cee/attachment.sig>


More information about the Digitalmars-d mailing list