Rename is_override to has_same_signature to correctly reflect behavior

Summary:
The problem with is_override that it can be misleading: it does not
check that that class of the first method is a subtype of the second; in
fact it totally ignores the classes.

This method is publicly exposed so lets just call what it does.

Reviewed By: jvillard

Differential Revision: D19724295

fbshipit-source-id: dc0919193
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent 4a08151851
commit 95d0e49c62

@ -337,17 +337,17 @@ let proc_calls resolve_attributes pdesc filter : (Procname.t * ProcAttributes.t)
List.iter ~f:do_node nodes ; List.rev !res List.iter ~f:do_node nodes ; List.rev !res
let is_override_of proc_name = let has_same_signature proc_name =
let sub_method_name = Procname.get_method proc_name in let method_name = Procname.get_method proc_name in
let sub_params = Procname.get_parameters proc_name in let params = Procname.get_parameters proc_name in
Staged.stage (fun super_pname -> Staged.stage (fun other_pname ->
let super_method_name = Procname.get_method super_pname in let other_method_name = Procname.get_method other_pname in
let super_params = Procname.get_parameters super_pname in let other_params = Procname.get_parameters other_pname in
(not (Procname.is_constructor super_pname)) (not (Procname.is_constructor other_pname))
&& String.equal super_method_name sub_method_name && String.equal other_method_name method_name
(* Check that parameter types match exactly (no subtyping or what not). *) (* Check that parameter types match exactly (no subtyping or what not). *)
&& &&
match List.for_all2 sub_params super_params ~f:Procname.Parameter.equal with match List.for_all2 params other_params ~f:Procname.Parameter.equal with
| List.Or_unequal_lengths.Ok res -> | List.Or_unequal_lengths.Ok res ->
res res
| List.Or_unequal_lengths.Unequal_lengths -> | List.Or_unequal_lengths.Unequal_lengths ->
@ -355,7 +355,7 @@ let is_override_of proc_name =
let override_find ?(check_current_type = true) f tenv proc_name = let override_find ?(check_current_type = true) f tenv proc_name =
let is_override = Staged.unstage (is_override_of proc_name) in let is_override = Staged.unstage (has_same_signature proc_name) in
let rec find_super_type super_class_name = let rec find_super_type super_class_name =
Tenv.lookup tenv super_class_name Tenv.lookup tenv super_class_name
|> Option.bind ~f:(fun {Struct.methods; supers} -> |> Option.bind ~f:(fun {Struct.methods; supers} ->

@ -153,6 +153,6 @@ val find_superclasses_with_attributes :
(Annot.Item.t -> bool) -> Tenv.t -> Typ.Name.t -> Typ.Name.t list (Annot.Item.t -> bool) -> Tenv.t -> Typ.Name.t -> Typ.Name.t list
(** find superclasss with attributes (e.g., [@ThreadSafe]), including current class*) (** find superclasss with attributes (e.g., [@ThreadSafe]), including current class*)
val is_override_of : Procname.t -> (Procname.t -> bool) Staged.t val has_same_signature : Procname.t -> (Procname.t -> bool) Staged.t
(** For a given [procname] checks if it's an override of some other [procname]. NOTE: the (** For a given [procname] checks if the method has the same method name, number, order and types of
implementation is not complete with respect to Java's generics and type erasure. *) parameters.) *)

@ -355,7 +355,7 @@ type annotation_trail = DirectlyAnnotated | Override of Procname.t | SuperClass
let find_override_or_superclass_annotated ~attrs_of_pname is_annot tenv proc_name = let find_override_or_superclass_annotated ~attrs_of_pname is_annot tenv proc_name =
let is_annotated pn = Annotations.pname_has_return_annot pn ~attrs_of_pname is_annot in let is_annotated pn = Annotations.pname_has_return_annot pn ~attrs_of_pname is_annot in
let is_override = Staged.unstage (PatternMatch.is_override_of proc_name) in let is_override = Staged.unstage (PatternMatch.has_same_signature proc_name) in
let rec find_override_or_superclass_aux class_name = let rec find_override_or_superclass_aux class_name =
match Tenv.lookup tenv class_name with match Tenv.lookup tenv class_name with
| None -> | None ->

Loading…
Cancel
Save