Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shapes::keyExists does not refine nested key information #9294

Open
muglug opened this issue Nov 8, 2022 · 2 comments
Open

Shapes::keyExists does not refine nested key information #9294

muglug opened this issue Nov 8, 2022 · 2 comments
Labels

Comments

@muglug
Copy link
Contributor

muglug commented Nov 8, 2022

Describe the bug
Originally reported by @eryi here: #8012 (comment)

Standalone code, or other way to reproduce the problem

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'];
}

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

@lexidor lexidor added the hack label Jun 13, 2023
@1samekhan
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants