diff --git a/infer/src/clang/ComponentKit.ml b/infer/src/clang/ComponentKit.ml index bd8a325b4..2ee8b1541 100644 --- a/infer/src/clang/ComponentKit.ml +++ b/infer/src/clang/ComponentKit.ml @@ -115,21 +115,12 @@ let component_factory_function_advice context decl = let is_component_if decl = Ast_utils.is_objc_if_descendant decl [CFrontend_config.ckcomponent_cl] in - let rec type_ptr_to_objc_if type_ptr = - let typ_opt = Ast_utils.get_desugared_type type_ptr in - match (typ_opt : Clang_ast_t.c_type option) with - | Some ObjCInterfaceType (_, decl_ptr) -> Ast_utils.get_decl decl_ptr - | Some ObjCObjectPointerType (_, (inner_qual_type: Clang_ast_t.qual_type)) -> - type_ptr_to_objc_if inner_qual_type.qt_type_ptr - | Some FunctionProtoType (_, function_type_info, _) - | Some FunctionNoProtoType (_, function_type_info) -> - type_ptr_to_objc_if function_type_info.Clang_ast_t.fti_return_type - | _ -> None in - match decl with | Clang_ast_t.FunctionDecl (decl_info, _, (qual_type: Clang_ast_t.qual_type), _) -> - let condition = is_ck_context context decl - && is_component_if (type_ptr_to_objc_if qual_type.qt_type_ptr) in + let objc_interface = + Ast_utils.type_ptr_to_objc_interface qual_type.qt_type_ptr in + let condition = + is_ck_context context decl && is_component_if objc_interface in if condition then Some { CIssue.issue = CIssue.Component_factory_function; diff --git a/infer/src/clang/cFrontend_utils.ml b/infer/src/clang/cFrontend_utils.ml index 50d7996b1..27cac18f3 100644 --- a/infer/src/clang/cFrontend_utils.ml +++ b/infer/src/clang/cFrontend_utils.ml @@ -460,6 +460,17 @@ struct || is_objc_if_descendant ~blacklist:blacklist (get_super_if if_decl) ancestors) | _ -> false + let rec type_ptr_to_objc_interface type_ptr = + let typ_opt = get_desugared_type type_ptr in + match (typ_opt : Clang_ast_t.c_type option) with + | Some ObjCInterfaceType (_, decl_ptr) -> get_decl decl_ptr + | Some ObjCObjectPointerType (_, (inner_qual_type: Clang_ast_t.qual_type)) -> + type_ptr_to_objc_interface inner_qual_type.qt_type_ptr + | Some FunctionProtoType (_, function_type_info, _) + | Some FunctionNoProtoType (_, function_type_info) -> + type_ptr_to_objc_interface function_type_info.Clang_ast_t.fti_return_type + | _ -> None + (* let rec getter_attribute_opt attributes = match attributes with diff --git a/infer/src/clang/cFrontend_utils.mli b/infer/src/clang/cFrontend_utils.mli index 2fa1d0d41..0f66528f6 100644 --- a/infer/src/clang/cFrontend_utils.mli +++ b/infer/src/clang/cFrontend_utils.mli @@ -171,6 +171,7 @@ sig val is_objc_if_descendant : ?blacklist:string list -> Clang_ast_t.decl option -> string list -> bool + val type_ptr_to_objc_interface : Clang_ast_types.t_ptr -> Clang_ast_t.decl option end module General_utils :