You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Shapes::keyExists does not refine nested key information #9294
Standalone code, or other way to reproduce the problem
functionmyfunc(shape(?'a' => shape(?'b' => string))$var): void {
if (!Shapes::keyExists($var, 'a')) thrownewException();
if (!Shapes::keyExists($var['a'], 'b')) thrownewException();
// Invalid index operation: 'optional' is marked as an optional shape field....echo$var['a']['b'];
}
Expected behavior
There should be no error
Actual behavior
File "/foo.hack", line 6, characters 18-20:
The field `b` may not be present in this shape. Use `Shapes::idx()` instead. (Typing[4165])
File "/foo.hack", line 1, characters 38-40:
This is where the field was declared as optional.
Environment
HipHop VM 4.172.0 (rel) (non-lowptr)
Compiler: 1667340154_989010953
Repo schema: 63eaf8b56fb7edbc7a8ca9e32786eb0c1f8f508c
function myfunc(shape(?'a' => shape(?'b' => string)) $var): void {
if (!Shapes::keyExists($var, 'a')) throw new Exception();
if (!Shapes::keyExists($var['a'], 'b')) throw new Exception();
// Invalid index operation: 'optional' is marked as an optional shape field....
echo $var['a']['b'];
}
File "/foo.hack", line 6, characters 18-20:
The field b may not be present in this shape. Use Shapes::idx() instead. (Typing[4165])
File "/foo.hack", line 1, characters 38-40:
This is where the field was declared as optional.
Activity
1samekhan commentedon Mar 7, 2024
function myfunc(shape(?'a' => shape(?'b' => string)) $var): void {
if (!Shapes::keyExists($var, 'a')) throw new Exception();
if (!Shapes::keyExists($var['a'], 'b')) throw new Exception();
// Invalid index operation: 'optional' is marked as an optional shape field....
echo $var['a']['b'];
}
1samekhan commentedon Mar 7, 2024
File "/foo.hack", line 6, characters 18-20:
The field
bmay not be present in this shape. UseShapes::idx()instead. (Typing[4165])File "/foo.hack", line 1, characters 38-40:
This is where the field was declared as optional.