Hi Stephen,

On Sun, Nov 6, 2016 at 4:44 PM, Stephen R. van den Berg <s...@cuci.nl> wrote:
> Why would you warn for this?
> Or, to put it differently: why would it be better to avoid using the
> dot operator to index dynamically?

 The problem mostly is that it is easy to mistake . as equivalent to
-> while it is not.

For example:

Pike v8.1 release 6 running Hilfe v3.5 (Incremental Pike Frontend)
> ADT.List l = ADT.List();
> l->insert(1);
Compiler Warning: 1: Returning a void expression. Converted to zero.
(1) Result: 0
> l.insert(2);
Compiler Warning: 1: Using . to index dynamically.
Bad argument 1 to `[](). Expected int.
Unknown program: `[]("insert")
-:1: ADT.List(/* 1 element */
    1
)->`[]("insert")
HilfeInput:1: HilfeInput()->___HilfeWrapper()

Another problem is that when . is used instead of -> on (object)
constants, you "suddenly" get a static index instead of a dynamic one.

I.e. imagine an environment where you have a constant object o of the
following program:

class X {
    array a = ({ });
}

Then the following will not work as one might expect:

o.a += ({ "hello" });
write("%O\n", o.a); // outputs the empty array

We have seen multiple issues with users stumbling over this in a bad way.

Reply via email to