Open
Description
Please complete the information below:
Where is the problem?
Bottom of the first example
What is the problem?
Shapes::idx
is for use with optional/nullable fields, not ones that aren't defined.
For example:
root@d32efb1aa9e9:~/hackdev/test# cat test.php
<?hh
function needs_nullable_string(?string $foo): void {
}
type TFoo = shape('somestr' => ?string, 'someint' => ?int);
function main(TFoo $x) {
needs_nullable_string(Shapes::idx($x, 'somestr')); // ok
some_undefined_func(Shapes::idx($x, 'nopenopenope')); // type error
}
main(shape());
root@d32efb1aa9e9:~/hackdev/test# hh_client
test.php:10:39,52: Invalid argument (Typing[4140])
test.php:8:15,18: The field 'nopenopenope' is missing
Please don't change anything below this point.
- Build ID: 2016-08-15T18:49:04+0000:e756f9162e96b867a06b2805e03056a63fc17931:2b940b7ef772640b5980b78c645f89cbd216d81f
- Page requested: /hack/reference/class/HH.Shapes/idx/
- Page requested at: Sun, 02 Oct 2016 04:02:07 +0000
- Controller: APIMethodPageController