On Monday, 18 May 2015 at 18:40:15 UTC, ketmar wrote:
On Mon, 18 May 2015 14:41:19 +0000, Chris wrote:

On Monday, 18 May 2015 at 14:34:38 UTC, ketmar wrote:
On Mon, 18 May 2015 14:30:42 +0000, Chris wrote:

The following

string[string] myarray = ["key":"value"];
string entry;
entry = myarray["key"]; // => vgc: indexing an associative array may
cause GC allocation

Why is _accessing_ an assoc treated as indexing it?

it can throw "out of range" error, which is `new`ed.

But shouldn't it read "accessing an associative array may cause GC
allocation"?

not any access may cause allocation. `auto e = "key" in myarray;` will not allocate, for example. yet it's still accessing the array. it's
*indexing* which may end in allocation.

Yes, that's exactly what was driving at. Accessing is not indexing, and yet I get a warning for _indexing_, while the real reason is that a wrong access can cause an exception (which allocates). I.e. it should be

"accessing an associative array may cause GC allocation on error"

Maybe the message with "indexing" for accessing is merely reusing the message for indexing, or all assoc array operations are lumped together as "indexing". I dunno. It seems wrong to me, because it's inaccurate.

And maybe a hint to the exception that may be thrown.
i believe that such explanation is a work for lint-like tool. burden
compiler with special cases can lead too far. ;-)

It's not the same as

myarray["key1] = "some value";
myarray["key2] = "some other value";

A bit confusing.

yes, it requires some knowledge of language and libraries. "-vgc" is not
a linter, though, it was made with some assumptions about user's
knowledge.

yet you can open ER in bugzilla, maybe DMD developers will implement it. i'm not a developer, and i can be wrong in reasons behind "-vgc".

Reply via email to