Use subtyping to typecheck dispatch calls for instance methods
commitb45b122ea93376d49e5fcdc053d0087ae287d5d8
authorHrutvik Kanabar <hrutvik@fb.com>
Thu, 17 Sep 2020 15:41:49 +0000 (17 08:41 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 17 Sep 2020 15:45:24 +0000 (17 08:45 -0700)
treecdc840afd06cc227e2dfbcbe26699a94cf99b8dd
parentfaf8315bff24ee831a7248d8e1884ffec52a8531
Use subtyping to typecheck dispatch calls for instance methods

Summary:
Instead of using `Typing_object_get.obj_get` to typecheck `Obj_get` method invocations in `dispatch_call`, create a `Thas_member` constraint and subtype it. This is similar to how property accesses are typechecked, see `Obj_get` property accesses in `expr_`.

We create a fresh type variable for the method type in the has-member constraint, and early-solve with respect to variance immediately after the subtyping check. Handling nullsafe behaviour is slightly different to property accesses: rather than making the whole method type nullable, we make only its return type nullable, only if the method receiver is nullable.

Reviewed By: CatherineGasnier

Differential Revision: D23102851

fbshipit-source-id: 3659ca50af7fac6a02ef4b00b7baacd912d69121
hphp/hack/src/typing/typing.ml
hphp/hack/src/typing/typing_subtype.ml