Skip to content

Commit c323851

Browse files
frank-emrichmeta-codesync[bot]
authored andcommitted
support for typedefs and typeconsts
Summary: This diff adds support for typedefs and typeconsts to `hh --find-my-tests`. For a typedef, `type Foo = ...`: - If `Foo` is directly mentioned in a test in any way, we select that test. - If `Foo` appears in the definition of another typedef `Bar` or typeconst `Bar::TBar`, we add `Bar`/`Bar::TBar` to our search. - If `Foo::class` or `nameof Foo` appears in the body of some method `m`, we add `m` to our search. For a tyepconst, `Foo::TFoo: - If `Foo::TFoo` is directly mentioned in a test in any way, we select that test. - If `Foo::TFoo` appears in the definition of another typedef `Bar` or typeconst `Bar::TBar`, we add `Bar`/`Bar::TBar` to our search. - If `type_structure(Foo::class, 'TFoo')` appears in some method `m`, we add `m` to our search. Implementation notes: - I've factored out some code shared by `get_method_references` and `get_class_references` into `get_references_standard`, which causes some noise in this diff. - The code for getting all references to a type constant `Foo::TFoo` (`get_typeconst_references`) is more complicated that code for other constructs: + For most heuristics, we need to find all references to `Foo::TFoo` directly. + For handling `type_structure(Foo::class, 'TFoo')`, we need to find all references to class `Foo`, and then inspect its use sites to look if it's one of the `type_structure` calls we are interested in. Reviewed By: madgen Differential Revision: D88656532 fbshipit-source-id: 6ce3bfebbe26f3adfc787e0cc26d78f27e133699
1 parent 5b0e305 commit c323851

19 files changed

Lines changed: 620 additions & 108 deletions

hphp/hack/src/client/clientCheck.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,10 +1043,12 @@ let main_internal
10431043
| Some "Method"
10441044
| None ->
10451045
Method { class_name; member_name }
1046+
| Some "Typeconst" -> Typeconst { class_name; member_name }
10461047
| Some _ -> raise Exit_status.(Exit_with Input_error))
10471048
~name_only_action:(fun name ->
10481049
match kind with
10491050
| Some "Class" -> Class { class_name = name }
1051+
| Some "Typedef" -> Typedef { name }
10501052
| Some _
10511053
| None ->
10521054
raise Exit_status.(Exit_with Input_error))

hphp/hack/src/client_and_server/serverCommandTypes.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ module Find_my_tests = struct
159159

160160
type action =
161161
| Class of { class_name: string }
162+
| Typedef of { name: string }
162163
| Method of member
164+
| Typeconst of member
163165
[@@deriving show]
164166

165167
type result_entry = {

0 commit comments

Comments
 (0)