flow icon indicating copy to clipboard operation
flow copied to clipboard

Objects participating in === comparison fail to typecheck

Open pasha-mf opened this issue 11 years ago • 5 comments

Test case:

var obj;
if (obj.x == 1);  // error: Property cannot be accessed on possibly undefined value
if (obj.x === 1); // no error ?!

(running Flow 0.14.0)

pasha-mf avatar Aug 20 '15 00:08 pasha-mf

See #698 :)

eyyub avatar Aug 20 '15 00:08 eyyub

I believe this is a different issue: the problem is not in accessing possibly non-existent property (x), but in accessing it on a possibly undefined object (obj). The code as written will cause a runtime error, Flow better warn me about this :)

pasha-mf avatar Aug 20 '15 00:08 pasha-mf

Yes indeed, sorry, my comment was not very comprehensible but I wanted to say that this is (a bug ?) caused by the refinement recently introduiced.

eyyub avatar Aug 20 '15 01:08 eyyub

This bug seems to be fixed in v0.21:

examples/01-variables/01-variables.js:31
 31: if (obj.x == 1);  // error: Property cannot be accessed on possibly undefined value
         ^^^^^ property `x`. Property not found in possibly undefined value
 31: if (obj.x == 1);  // error: Property cannot be accessed on possibly undefined value
         ^^^ uninitialized variable

examples/01-variables/01-variables.js:32
 32: if (obj.x === 1); // no error ?!
         ^^^^^ property `x`. Property not found in possibly undefined value
 32: if (obj.x === 1); // no error ?!
         ^^^ uninitialized variable

examples/01-variables/01-variables.js:32
 32: if (obj.x === 1); // no error ?!
             ^ property `x`. Property not found in possibly undefined value
 32: if (obj.x === 1); // no error ?!
         ^^^ uninitialized variable

raquo avatar Feb 14 '16 03:02 raquo

@pasha-mf gonna close this based on @raquo's comment, but please let me know if it's not fixed

mroch avatar May 31 '16 23:05 mroch