Readonly closure calls
commit84b52cc82d05f99011d1ee0204069065484bd92b
authorJames Wu <jjwu@fb.com>
Thu, 8 Apr 2021 17:43:54 +0000 (8 10:43 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 8 Apr 2021 17:46:47 +0000 (8 10:46 -0700)
treea91a2c0cb11824ccc7129364b74366a7114c6774
parent181e36f655a59fbc7c7dbab3d2405fec2e16f998
Readonly closure calls

Summary:
This diff forbids a readonly closure that was not marked readonly at the declaration site to be called. Since this is relatively confusing behavior, the error message tries to suggest reasonable alternatives when trying to call a readonly closure.

- If it sees the readonly closure from a typehint, it will suggest marking the typehint as `(readonly function() : ..)`.
- If it sees the readonly closure from a declaration it will suggest adding readonly to the declaration.

Note that this does not handle more complex cases where the type is not a single Tfun but a Tunion or Tintersection: I will address this in a later diff.

Reviewed By: losvald

Differential Revision: D27304014

fbshipit-source-id: 5625c5dd256caf58aa97f22d94093744ed1bdd1f
hphp/hack/src/errors/error_codes.ml
hphp/hack/src/errors/errors.ml
hphp/hack/src/errors/errors.mli
hphp/hack/src/oxidized/gen/error_codes.rs
hphp/hack/src/typing/tast_check/readonly_check.ml
hphp/hack/src/typing/typing_print.ml
hphp/hack/test/typecheck/readonly/call.php
hphp/hack/test/typecheck/readonly/call.php.exp
hphp/hack/test/typecheck/readonly/call.php.like_types.exp [new file with mode: 0644]