From 80f511d6396789f346a39f3ce8d8145804c09121 Mon Sep 17 00:00:00 2001 From: Alex Kassil Date: Tue, 5 Dec 2023 19:34:46 -0800 Subject: [PATCH] Refactor `receiver_class_from_type` Summary: This reduces the level of nesting Reviewed By: arthaud Differential Revision: D51828242 fbshipit-source-id: 2e9b59deaa1468217f4817b1834eaf77f52459b7 --- source/interprocedural/callGraph.ml | 34 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/source/interprocedural/callGraph.ml b/source/interprocedural/callGraph.ml index f487287ca92..366582ada87 100644 --- a/source/interprocedural/callGraph.ml +++ b/source/interprocedural/callGraph.ml @@ -188,24 +188,22 @@ module CallTarget = struct let receiver_class_from_type ~is_class_method annotation = - let type_, parameters = - annotation - |> CallResolution.strip_optional - |> CallResolution.strip_readonly - |> CallResolution.unbind_type_variable - |> Type.split - in - match Type.primitive_name type_ with - | Some "type" -> ( - match parameters with - | [Type.Record.Parameter.Single parameter] when is_class_method -> - (* The receiver is the class itself. Technically, the receiver class type should be - `Type[int]`. However, we strip away the `type` part since it is implied by the - `is_class_method` flag. *) - Type.primitive_name parameter - | _ -> None) - | Some "super" -> None - | name -> name + annotation + |> CallResolution.strip_optional + |> CallResolution.strip_readonly + |> CallResolution.unbind_type_variable + |> Type.split + |> fun (annotation, parameters) -> + (Type.primitive_name annotation, parameters) + |> function + | Some "type", [Type.Record.Parameter.Single parameter] when is_class_method -> + (* The receiver is the class itself. Technically, the receiver class type should be + `Type[int]`. However, we strip away the `type` part since it is implied by the + `is_class_method` flag. *) + Type.primitive_name parameter + | Some "type", _ -> None + | Some "super", _ -> None + | name, _ -> name let create