Skip to content

Commit

Permalink
[self-in-block] Only do autofixes for Mixed Self weakSelf when the lo…
Browse files Browse the repository at this point in the history
…cation of self doesn't come from a macro expansion.

Summary: When the code comes from a macro expansion we can't tell what the syntactical line and column is precisely, so we avoid computing autofixes in that case.

Reviewed By: geralt-encore

Differential Revision: D64325410

fbshipit-source-id: 1b7f4cc407ce176beb62372d1cdba2190ec75ee3
  • Loading branch information
dulmarod authored and facebook-github-bot committed Oct 14, 2024
1 parent ed0951c commit 513460b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion infer/src/checkers/SelfInBlock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ let report_mix_self_weakself_issues proc_desc err_log domain (weakSelf : DomainD
let autofix =
Option.bind
~f:(fun (strongSelf, strongSelfLoc) ->
if strongSelfLoc.Location.line < self.loc.line && Pvar.is_syntactic self.pvar then
if
strongSelfLoc.Location.line < self.loc.line
&& Pvar.is_syntactic self.pvar
&& Option.is_none self.loc.Location.macro_file_opt
then
Some
{ Jsonbug_j.original= Some (to_string self.DomainData.pvar)
; replacement= Some (to_string strongSelf)
Expand Down
5 changes: 4 additions & 1 deletion infer/tests/codetoanalyze/objc/self-in-block/StrongSelf.m
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ - (void)mixSelfWeakSelf_bad_correct_autofix_macro {

#define MY_LOG(format, ...) NSLog(format, ##__VA_ARGS__)

- (void)mixSelfWeakSelf_bad_wrong_autofix_column {
// When the code comes from a macro expansion we can't tell what
// the syntactical line and column is precisely, so we avoid computing autofixes
// in that case.
- (void)mixSelfWeakSelf_bad_no_autofix_macro {
__weak __typeof(self) weakSelf = self;
int (^my_block)() = ^() {
__strong __typeof(weakSelf) strongSelf = weakSelf;
Expand Down
6 changes: 3 additions & 3 deletions infer/tests/codetoanalyze/objc/self-in-block/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:245, 2, C
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:288, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:303, 1, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &self,Using &weakSelf]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:339, 3, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [macro expanded here,Using &weakSelf,Using &self], "self"=>"strongSelf"@342:6
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:350, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,macro expanded here,Using &self], "self"=>"strongSelf"@354:7
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:362, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self], "self"=>"strongSelf"@366:7
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:377, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:353, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,macro expanded here,Using &self]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:365, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self], "self"=>"strongSelf"@369:7
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:380, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self]

0 comments on commit 513460b

Please sign in to comment.