Extending type matching to BlockExpr

Reviewed By: jvillard

Differential Revision: D10853084

fbshipit-source-id: 231cf4693
master
Dino Distefano 6 years ago committed by Facebook Github Bot
parent 6cce767d19
commit 6fe3edc44e

@ -489,7 +489,9 @@ and c_type_equal c_type abs_ctype =
| LValueReferenceType (_, qt), Reference abs_typ | RValueReferenceType (_, qt), Reference abs_typ
->
check_type_ptr qt.qt_type_ptr abs_typ
| ObjCObjectPointerType (_, qt), ObjCGenProt _ ->
| BlockPointerType (_, qt), TypeName _
| FunctionProtoType (_, {fti_return_type= qt}, _), TypeName _
| ObjCObjectPointerType (_, qt), _ ->
check_type_ptr qt.qt_type_ptr abs_ctype
| ObjCObjectType _, ObjCGenProt _ ->
objc_object_type_equal c_type abs_ctype

@ -0,0 +1,109 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
@interface CKComponent : NSObject
@end
@implementation CKComponent
@end
typedef CKComponent* (^FBSectionComponentGenerator)(id<NSObject> model,
id<NSObject> context);
struct TestComponentOptions {
id componentGenerator;
};
@interface TestComponent : NSObject
+ (instancetype)newWithComponentGenerator:
(FBSectionComponentGenerator)generator;
+ (instancetype)newWithOptions:(TestComponentOptions)options;
@end
@implementation TestComponent
+ (instancetype)newWithComponentGenerator:
(FBSectionComponentGenerator)generator {
return [self new];
}
+ (instancetype)newWithOptions:(TestComponentOptions)options {
return [self new];
}
@end
__unused static void testBadValDecl() {
NSObject* obj = [NSObject new];
__unused TestComponent* component = [TestComponent
newWithComponentGenerator:^CKComponent*(id<NSObject> m, id<NSObject> c) {
__unused NSObject* innerObj = obj;
return nil;
}];
}
__unused static void testBadStructValDecl() {
NSObject* obj = [NSObject new];
__unused TestComponent *component =
[TestComponent
newWithOptions:{
.componentGenerator = ^CKComponent *(id<NSObject> m, id<NSObject> c) {
__unused NSObject *innerObj = obj;
return nil;
}
,
}];
}
__unused static void testBadNonValDecl() {
NSObject* obj = [NSObject new];
__unused TestComponent* component = nil;
component = [TestComponent
newWithComponentGenerator:^CKComponent*(id<NSObject> m, id<NSObject> c) {
__unused id<NSObject> innerObj = obj;
return nil;
}];
}
__unused static void testBadStructNonValDecl() {
NSObject* obj = [NSObject new];
__unused TestComponent* component = nil;
component =
[TestComponent
newWithOptions:{
.componentGenerator = ^CKComponent *(id<NSObject> m, id<NSObject> c) {
__unused NSObject *innerObj = obj;
return nil;
}
,
}];
}
__unused static void testOK() {
__unused TestComponent* component = [TestComponent
newWithComponentGenerator:^CKComponent*(id<NSObject> m, id<NSObject> c) {
__unused id<NSObject> innerObj = m;
return nil;
}];
}
__unused static void testOKStruct() {
__unused TestComponent *component =
[TestComponent
newWithOptions:{
.componentGenerator = ^CKComponent *(id<NSObject> m, id<NSObject> c) {
__unused id<NSObject> innerObj = m;
return nil;
}
,
}];
}

@ -26,6 +26,10 @@ codetoanalyze/objcpp/linters-for-test-only/TestStructFieldChecks.mm, Linters_dum
codetoanalyze/objcpp/linters-for-test-only/TestStructFieldChecks.mm, buttonComponent, 31, TITLE_NOT_INITIALIZED, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/TestStructFieldChecks.mm, buttonComponent, 33, TITLE_NOT_INITIALIZED, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/TestStructFieldChecks.mm, buttonComponent, 37, TITLE_NOT_INITIALIZED, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/componentblock.mm, objc_block_2, 48, OBJC_BLOCK_CAPTURING_VALUES, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/componentblock.mm, objc_block_3, 59, OBJC_BLOCK_CAPTURING_VALUES, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/componentblock.mm, objc_block_4, 71, OBJC_BLOCK_CAPTURING_VALUES, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/componentblock.mm, objc_block_5, 83, OBJC_BLOCK_CAPTURING_VALUES, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/hash_test.mm, std::hash_NSObject_*__operator(), 12, DISCOURAGED_HASH_METHOD_INVOCATION, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/stateless.m, Linters_dummy_method, 21, ADHERE_TO_PROTOCOL, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/stateless.m, Linters_dummy_method, 24, ONLY_ONE_CLASS_METHOD, no_bucket, WARNING, []

Loading…
Cancel
Save