Fix nullable field type checking for Shapes::idx
commit12ebf0fdf354818ed03946bc1e540c550dafa327
authorArun Kumar <arkumar@fb.com>
Tue, 22 Aug 2017 08:09:40 +0000 (22 01:09 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Tue, 22 Aug 2017 08:32:19 +0000 (22 01:32 -0700)
tree55c41e091a0f9031b6e0b89d84402cbe7e82f1ca
parente38df9e00cc3a5a9b7800cd4416783c19988f9e7
Fix nullable field type checking for Shapes::idx

Summary:
Consider the following function.
```
<?hh // strict

function test(shape('x' => ?string) $s): string {
  return Shapes::idx($s, 'x', 'default');
}
```

This type checks correctly. However, Shapes::idx($s, 'x', 'default') will return null if $s is provided as shape('x' => null). The type checker thinks it returns string, when in fact it returns ?string. This is a bug in the type checker that we need to fix.

Reviewed By: michaeltingley

Differential Revision: D5615771

fbshipit-source-id: 1bfeca3f603a8dbbdfba11d4780c71be9e307769
25 files changed:
hphp/hack/src/typing/typing_shapes.ml
hphp/hack/test/typecheck/shape/shape_idx_nullable_field_with_default_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_nullable_field_with_default_return.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_nullable_field_with_nullable_default_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_nullable_field_with_nullable_default_return.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_nullable_optional_field_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_nullable_optional_field_return.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_nullable_optional_field_with_default_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_nullable_optional_field_with_default_return.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_nullable_optional_field_with_nullable_default_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_nullable_optional_field_with_nullable_default_return.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_optional_field_default_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_optional_field_default_return.php.exp [copied from hphp/hack/test/typecheck/shape/shapes_idx_returns_correct_type_for_optional_and_nullable_fields.php.exp with 100% similarity]
hphp/hack/test/typecheck/shape/shape_idx_optional_field_with_nullable_default_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_optional_field_with_nullable_default_return.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_optional_nullable_field_with_default_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_optional_nullable_field_with_default_return.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_required_field_return.php
hphp/hack/test/typecheck/shape/shape_idx_required_field_with_default_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_required_field_with_default_return.php.exp [copied from hphp/hack/test/typecheck/shape/shapes_idx_returns_correct_type_for_optional_and_nullable_fields.php.exp with 100% similarity]
hphp/hack/test/typecheck/shape/shape_idx_required_field_with_nullable_default_return.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_required_field_with_nullable_default_return.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_returns_correct_types.php [new file with mode: 0644]
hphp/hack/test/typecheck/shape/shape_idx_returns_correct_types.php.exp [moved from hphp/hack/test/typecheck/shape/shapes_idx_returns_correct_type_for_optional_and_nullable_fields.php.exp with 100% similarity]
hphp/hack/test/typecheck/shape/shapes_idx_returns_correct_type_for_optional_and_nullable_fields.php [deleted file]