From 72802024b37b935d7ccbe40d0c2e863d94940515 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Wed, 21 Jun 2017 10:47:56 -0700 Subject: [PATCH] [linters] Fix unavailable api check to take the avaiability attribute into account when it's not the first one in the list. Reviewed By: martinoluca Differential Revision: D5292444 fbshipit-source-id: 620a855 --- infer/src/clang/cPredicates.ml | 4 +-- .../codetoanalyze/objc/ioslints/issues.exp | 1 + .../objc/ioslints/unavailable_property_ios.m | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 infer/tests/codetoanalyze/objc/ioslints/unavailable_property_ios.m diff --git a/infer/src/clang/cPredicates.ml b/infer/src/clang/cPredicates.ml index 0163038aa..5cd370c7e 100644 --- a/infer/src/clang/cPredicates.ml +++ b/infer/src/clang/cPredicates.ml @@ -20,12 +20,12 @@ let get_available_attr_ios_sdk an = let rec get_available_attr attrs = match attrs with | [] -> None - | AvailabilityAttr attr_info :: _ -> + | AvailabilityAttr attr_info :: rest -> (match attr_info.ai_parameters with | "ios" :: version :: _ -> Some (String.Search_pattern.replace_all (String.Search_pattern.create "_") ~in_:version ~with_:".") - | _ -> None) + | _ -> get_available_attr rest) | _ :: rest -> get_available_attr rest in match an with | Ctl_parser_types.Decl decl -> diff --git a/infer/tests/codetoanalyze/objc/ioslints/issues.exp b/infer/tests/codetoanalyze/objc/ioslints/issues.exp index 2f4907f14..215a9652f 100644 --- a/infer/tests/codetoanalyze/objc/ioslints/issues.exp +++ b/infer/tests/codetoanalyze/objc/ioslints/issues.exp @@ -5,3 +5,4 @@ codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_all codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_responds_to_selector:, 64, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, OpenURLOptionsFromSourceApplication, 26, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_test:and:, 19, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] +codetoanalyze/objc/ioslints/unavailable_property_ios.m, FNFPlayerLayer_initWithConfigs:, 22, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] diff --git a/infer/tests/codetoanalyze/objc/ioslints/unavailable_property_ios.m b/infer/tests/codetoanalyze/objc/ioslints/unavailable_property_ios.m new file mode 100644 index 000000000..44a72cf6f --- /dev/null +++ b/infer/tests/codetoanalyze/objc/ioslints/unavailable_property_ios.m @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#import + +@interface FNFPlayerLayer : CAEAGLLayer + +- (instancetype)initWithConfigs:(FNFPlayerLayer*)configs; + +@end + +@implementation FNFPlayerLayer { + BOOL my_field; +} + +- (instancetype)initWithConfigs:(FNFPlayerLayer*)configs { + my_field = configs.presentsWithTransaction; + return self; +} + +@end