Skip to content

Commit

Permalink
[self-in-block] Report all the instances of self use in Mixed self we…
Browse files Browse the repository at this point in the history
…akSelf

Summary: We were returning only one instance so far. We want to return all because now we are interested in fixing all instances with autofixes and codemods.

Reviewed By: skcho

Differential Revision: D65151572

fbshipit-source-id: 8d40c21985ca85a055e67013540b54c06f5dcc6b
  • Loading branch information
dulmarod authored and facebook-github-bot committed Oct 30, 2024
1 parent 283ef2a commit 6d32e45
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
15 changes: 9 additions & 6 deletions infer/src/checkers/SelfInBlock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,15 @@ let report_issues proc_desc err_log domain =
let {weakSelfList; selfList} =
List.fold_left ~f:process_domain_item ~init:report_issues_result_empty domain_bindings
in
let weakSelfList = List.rev weakSelfList in
let selfList = List.rev selfList in
( match (weakSelfList, selfList) with
| weakSelf :: _, self :: _ ->
report_mix_self_weakself_issues proc_desc err_log domain weakSelf self
| _ ->
let weakSelfList =
List.sort
~compare:(fun el1 el2 -> Location.compare el1.DomainData.loc el2.DomainData.loc)
weakSelfList
in
( match List.hd weakSelfList with
| Some weakSelf ->
List.iter ~f:(report_mix_self_weakself_issues proc_desc err_log domain weakSelf) selfList
| None ->
() ) ;
match weakSelfList with
| weakSelf1 :: weakSelf2 :: _ ->
Expand Down
1 change: 1 addition & 0 deletions infer/tests/codetoanalyze/objc/self-in-block/StrongSelf.m
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ - (void)mixSelfWeakSelf_bad_autofix_implicit_self {
if (strongSelf) {
[strongSelf foo];
_name = @"Dulma";
x = 10;
}
return 0;
};
Expand Down
6 changes: 4 additions & 2 deletions infer/tests/codetoanalyze/objc/self-in-block/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ codetoanalyze/objc/self-in-block/NoescapeBlock.m, objc_block_NoescapeBlock.m:89,
codetoanalyze/objc/self-in-block/SelfInBlockPassedToInit.m, objc_block_SelfInBlockPassedToInit.m:17, 1, SELF_IN_BLOCK_PASSED_TO_INIT, no_bucket, ERROR, [Using captured &self,Using captured &self]
codetoanalyze/objc/self-in-block/SelfInBlockPassedToInit.m, objc_block_SelfInBlockPassedToInit.m:17, 2, SELF_IN_BLOCK_PASSED_TO_INIT, no_bucket, ERROR, [Using captured &self,Using captured &self]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:65, 4, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self,Using &self], "self"=>"strongSelf"@69:15
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:65, 5, MIXED_SELF_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &self,Using &self], "self"=>"strongSelf"@70:8
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:78, 1, CAPTURED_STRONG_SELF, no_bucket, ERROR, [Using captured &weakSelf]
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:106, 6, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [&strongSelf assigned here,Using &strongSelf not checked for null,Using &strongSelf not checked for null], +""=>"\n if (!strongSelf) { return; }"@108:1
codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:121, 6, STRONG_SELF_NOT_CHECKED, no_bucket, ERROR, [&strongSelf assigned here,Using &strongSelf not checked for null,Using &strongSelf not checked for null]
Expand All @@ -20,5 +21,6 @@ codetoanalyze/objc/self-in-block/StrongSelf.m, objc_block_StrongSelf.m:288, 4, M
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: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], ""=>"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]
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]

0 comments on commit 6d32e45

Please sign in to comment.