Skip to content

Commit

Permalink
[self-in-block] Add example of when we report two instances of strong…
Browse files Browse the repository at this point in the history
…Self Not Checked

Summary: We want to report only once per strongSelf variable, otherwise the autofix will create two separate if conditions in codemods. Adding a test that shows when we are reporting twice now, when each usage is in a different if branch.

Reviewed By: skcho

Differential Revision: D65156544

fbshipit-source-id: 6469285de66e2c81026f41edbf14230fe373cbb5
  • Loading branch information
dulmarod authored and facebook-github-bot committed Oct 30, 2024
1 parent 6d32e45 commit 249de1f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions infer/tests/codetoanalyze/objc/self-in-block/StrongSelf.m
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,28 @@ - (void)mixSelfWeakSelf_bad_no_autofix_super_property {
};
}

- (void)strongSelfNoCheck2Instances_bad {
__weak __typeof(self) weakSelf = self;
int (^my_block)(BOOL) = ^(BOOL isTapped) {
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (isTapped) {
strongSelf->_name = @"Dulma";
} else {
strongSelf->_name = @"Alice";
}
return 0;
};
}

- (void)strongSelfNoCheck2InstancesNoIf_bad {
__weak __typeof(self) weakSelf = self;
int (^my_block)(BOOL) = ^(BOOL isTapped) {
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (isTapped) {
strongSelf->_name = @"Dulma";
strongSelf->_name = @"Alice";
}
return 0;
};
}
@end
3 changes: 3 additions & 0 deletions infer/tests/codetoanalyze/objc/self-in-block/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:353, 4, M
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:365, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self,Using &self], ""=>"strongSelf->"@369:7
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:365, 5, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self,Using &self], ""=>"strongSelf->"@370:7
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:381, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:393, 3, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [&strongSelf assigned here,Using &strongSelf not checked for null]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:393, 5, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [&strongSelf assigned here,Using &strongSelf not checked for null]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:406, 3, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [&strongSelf assigned here,Using &strongSelf not checked for null]

0 comments on commit 249de1f

Please sign in to comment.