diff --git a/infer/src/checkers/patternMatch.ml b/infer/src/checkers/patternMatch.ml index a14f52b84..533203a49 100644 --- a/infer/src/checkers/patternMatch.ml +++ b/infer/src/checkers/patternMatch.ml @@ -98,29 +98,6 @@ let type_get_annotation tenv (typ: Typ.t): Annot.Item.t option = ) | _ -> None -let type_has_direct_supertype tenv (typ : Typ.t) (class_name : Typ.Name.t) = - List.exists ~f:(fun cn -> Typ.Name.equal cn class_name) (type_get_direct_supertypes tenv typ) - -let type_has_supertype - (tenv: Tenv.t) - (typ: Typ.t) - (class_name: Typ.Name.t): bool = - let rec has_supertype typ visited = - if Typ.Set.mem typ visited then - false - else - let supers = type_get_direct_supertypes tenv typ in - let match_supertype cn = - let match_name () = Typ.Name.equal cn class_name in - let has_indirect_supertype () = has_supertype (Typ.mk (Tstruct cn)) (Typ.Set.add typ visited) in - (match_name () || has_indirect_supertype ()) in - List.exists ~f:match_supertype supers in - has_supertype typ Typ.Set.empty - -let type_is_nested_in_direct_supertype tenv t n = - let is_nested_in cn1 cn2 = String.is_prefix ~prefix:(Typ.Name.name cn1 ^ "$") (Typ.Name.name cn2) in - List.exists ~f:(is_nested_in n) (type_get_direct_supertypes tenv t) - let rec get_type_name {Typ.desc} = match desc with | Typ.Tstruct name -> @@ -272,11 +249,14 @@ let initializer_methods = [ ] (** Check if the type has in its supertypes from the initializer_classes list. *) -let type_has_initializer - (tenv: Tenv.t) - (t: Typ.t): bool = - let check_candidate class_name = type_has_supertype tenv t class_name in - List.exists ~f:check_candidate initializer_classes +let type_has_initializer (tenv: Tenv.t) (t: Typ.t): bool = + let is_initializer_class typename _ = + List.mem ~equal:Typ.Name.equal initializer_classes typename in + match t.desc with + | Typ.Tstruct name | Tptr ({ desc=Tstruct name}, _) -> + supertype_exists tenv is_initializer_class name + | _ -> + false (** Check if the method is one of the known initializer methods. *) let method_is_initializer diff --git a/infer/src/checkers/patternMatch.mli b/infer/src/checkers/patternMatch.mli index f5bedd884..79e70ff91 100644 --- a/infer/src/checkers/patternMatch.mli +++ b/infer/src/checkers/patternMatch.mli @@ -95,15 +95,9 @@ val type_get_annotation : Tenv.t -> Typ.t -> Annot.Item.t option (** Get the class name of the type *) val type_get_class_name : Typ.t -> Typ.Name.t option -val type_get_direct_supertypes : Tenv.t -> Typ.t -> Typ.Name.t list - -val type_has_direct_supertype : Tenv.t -> Typ.t -> Typ.Name.t -> bool - (** Is the type a class type *) val type_is_class : Typ.t -> bool -val type_is_nested_in_direct_supertype : Tenv.t -> Typ.t -> Typ.Name.t -> bool - (** Is the type java.lang.Object *) val type_is_object : Typ.t -> bool