diff --git a/infer/src/clang/cFrontend_checkers_main.ml b/infer/src/clang/cFrontend_checkers_main.ml index 354033eed..4252f1cbc 100644 --- a/infer/src/clang/cFrontend_checkers_main.ml +++ b/infer/src/clang/cFrontend_checkers_main.ml @@ -46,6 +46,7 @@ let rec get_responds_to_selector stmt = let open Clang_ast_t in match stmt with | ObjCMessageExpr (_, [_; ObjCSelectorExpr (_, _, _, method_name)], _, mdi) + | ObjCMessageExpr (_, [ObjCSelectorExpr (_, _, _, method_name)], _, mdi) when String.equal mdi.Clang_ast_t.omei_selector "respondsToSelector:" -> [method_name] | BinaryOperator (_, [stmt1;stmt2], _, bo_info) diff --git a/infer/tests/codetoanalyze/objc/iosLinters/unavailable_api_allowed_cases.m b/infer/tests/codetoanalyze/objc/iosLinters/unavailable_api_allowed_cases.m index e4f355bcf..2391f3c46 100644 --- a/infer/tests/codetoanalyze/objc/iosLinters/unavailable_api_allowed_cases.m +++ b/infer/tests/codetoanalyze/objc/iosLinters/unavailable_api_allowed_cases.m @@ -73,4 +73,17 @@ } } +// no bug +- (void)uifont_with_respondstoselector:(CGFloat)size { + UIFont* font; + if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) { + font = [UIFont systemFontOfSize:size weight:0]; + } +} + +// bug +- (void)uifont_without_respondstoselector:(CGFloat)size { + UIFont* font = [UIFont systemFontOfSize:size weight:0]; +} + @end diff --git a/infer/tests/codetoanalyze/objc/ioslinters/issues.exp b/infer/tests/codetoanalyze/objc/ioslinters/issues.exp index 9d08b1ba4..4ccf7fa1a 100644 --- a/infer/tests/codetoanalyze/objc/ioslinters/issues.exp +++ b/infer/tests/codetoanalyze/objc/ioslinters/issues.exp @@ -1,3 +1,4 @@ +codetoanalyze/objc/ioslinters/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_uifont_without_respondstoselector:, 86, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslinters/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_with_responds_to_selector_in_else:, 52, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslinters/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_responds_to_selector:, 45, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslinters/unavailable_api_in_supported_ios_sdk.m, OpenURLOptionsFromSourceApplication, 18, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []