Skip to content

Commit

Permalink
Refactor receiver_class_from_type
Browse files Browse the repository at this point in the history
Summary: This reduces the level of nesting

Reviewed By: arthaud

Differential Revision: D51828242

fbshipit-source-id: 2e9b59deaa1468217f4817b1834eaf77f52459b7
  • Loading branch information
alexkassil authored and facebook-github-bot committed Dec 6, 2023
1 parent 894a4c8 commit 80f511d
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions source/interprocedural/callGraph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 80f511d

Please sign in to comment.