From 95d0e49c62b0db6fc7c85ff1e884f727a9671f29 Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Wed, 5 Feb 2020 06:21:35 -0800 Subject: [PATCH] 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 --- infer/src/absint/PatternMatch.ml | 20 ++++++++++---------- infer/src/absint/PatternMatch.mli | 6 +++--- infer/src/concurrency/ConcurrencyModels.ml | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/infer/src/absint/PatternMatch.ml b/infer/src/absint/PatternMatch.ml index 81d7aa490..6a6c1ce69 100644 --- a/infer/src/absint/PatternMatch.ml +++ b/infer/src/absint/PatternMatch.ml @@ -337,17 +337,17 @@ let proc_calls resolve_attributes pdesc filter : (Procname.t * ProcAttributes.t) List.iter ~f:do_node nodes ; List.rev !res -let is_override_of proc_name = - let sub_method_name = Procname.get_method proc_name in - let sub_params = Procname.get_parameters proc_name in - Staged.stage (fun super_pname -> - let super_method_name = Procname.get_method super_pname in - let super_params = Procname.get_parameters super_pname in - (not (Procname.is_constructor super_pname)) - && String.equal super_method_name sub_method_name +let has_same_signature proc_name = + let method_name = Procname.get_method proc_name in + let params = Procname.get_parameters proc_name in + Staged.stage (fun other_pname -> + let other_method_name = Procname.get_method other_pname in + let other_params = Procname.get_parameters other_pname in + (not (Procname.is_constructor other_pname)) + && String.equal other_method_name method_name (* 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 -> res | 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 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 = Tenv.lookup tenv super_class_name |> Option.bind ~f:(fun {Struct.methods; supers} -> diff --git a/infer/src/absint/PatternMatch.mli b/infer/src/absint/PatternMatch.mli index 770669516..5d871f81c 100644 --- a/infer/src/absint/PatternMatch.mli +++ b/infer/src/absint/PatternMatch.mli @@ -153,6 +153,6 @@ val find_superclasses_with_attributes : (Annot.Item.t -> bool) -> Tenv.t -> Typ.Name.t -> Typ.Name.t list (** find superclasss with attributes (e.g., [@ThreadSafe]), including current class*) -val is_override_of : Procname.t -> (Procname.t -> bool) Staged.t -(** For a given [procname] checks if it's an override of some other [procname]. NOTE: the - implementation is not complete with respect to Java's generics and type erasure. *) +val has_same_signature : Procname.t -> (Procname.t -> bool) Staged.t +(** For a given [procname] checks if the method has the same method name, number, order and types of + parameters.) *) diff --git a/infer/src/concurrency/ConcurrencyModels.ml b/infer/src/concurrency/ConcurrencyModels.ml index db8be1b70..438e24fb4 100644 --- a/infer/src/concurrency/ConcurrencyModels.ml +++ b/infer/src/concurrency/ConcurrencyModels.ml @@ -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 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 = match Tenv.lookup tenv class_name with | None ->