Throw error when using meth_caller with non-public methodsnightly-2021.05.04
commitf393d57663decb25a666851904db1ef4c5e93c04
authorThomas Jiang <thomasjiang@fb.com>
Tue, 4 May 2021 02:04:21 +0000 (3 19:04 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 4 May 2021 02:05:47 +0000 (3 19:05 -0700)
tree9e596e8764b9dd975ea900c7c78d9d4a4cd82d5d
parentea1f6279c926663e55a80c0a5faefc470723229b
Throw error when using meth_caller with non-public methods

Summary:
Currently, Hack does not throw an error if you use `meth_caller` on a public or private method from within the same class hierarchy.

```
class Foo extends MyChild {
  protected function bar(): void {}
  private function baz(): void {}

  public function test(): void {
    $y = meth_caller(Foo::class, 'bar');
    $z = meth_caller(Foo::class, 'baz');
  }
}
```

Currently, using this reference will result in a HHVM runtime error, as we don't support this yet. We will in the future, so make this controllable via an option in both `hh_single_type_check` and `.hhconfig` so that we don't need another release to change this in the future.

`hh_single_type_check --meth_caller_only_public_visibility=false $t`

and the

`meth_caller_only_public_visibility = false`

option in `.hhconfig` will stop Hack from throwing these errors.

Reviewed By: periodic1236

Differential Revision: D28136384

fbshipit-source-id: 4aa9d8cc085c51a22ad92776d3a787c7e715d941
31 files changed:
hphp/hack/src/errors/error_codes.ml
hphp/hack/src/errors/errors.ml
hphp/hack/src/errors/errors.mli
hphp/hack/src/hh_single_decl.ml
hphp/hack/src/hh_single_type_check.ml
hphp/hack/src/options/globalOptions.ml
hphp/hack/src/options/globalOptions.mli
hphp/hack/src/options/typecheckerOptions.ml
hphp/hack/src/oxidized/gen/error_codes.rs
hphp/hack/src/oxidized/gen/global_options.rs
hphp/hack/src/oxidized/manual/global_options_impl.rs
hphp/hack/src/oxidized_by_ref/gen/global_options.rs
hphp/hack/src/oxidized_by_ref/manual/global_options_impl.rs
hphp/hack/src/server/serverConfig.ml
hphp/hack/src/typing/typing.ml
hphp/hack/src/typing/typing_memoize.ml
hphp/hack/src/typing/typing_object_get.ml
hphp/hack/src/typing/typing_object_get.mli
hphp/hack/src/typing/typing_subtype.ml
hphp/hack/src/typing/typing_visibility.ml
hphp/hack/src/typing/typing_visibility.mli
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/HH_FLAGS [new file with mode: 0644]
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/default/HH_FLAGS [new file with mode: 0644]
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/default/meth_caller_visibility.php [new file with mode: 0644]
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/default/meth_caller_visibility.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/default/meth_caller_visibility_errors.php [new file with mode: 0644]
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/default/meth_caller_visibility_errors.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/meth_caller_visibility.php [new file with mode: 0644]
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/meth_caller_visibility.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/meth_caller_visibility_errors.php [new file with mode: 0644]
hphp/hack/test/typecheck/function_pointer/meth_caller_visibility/meth_caller_visibility_errors.php.exp [new file with mode: 0644]