File tree Expand file tree Collapse file tree 2 files changed +42
-6
lines changed
infer/documentation/issues Expand file tree Collapse file tree 2 files changed +42
-6
lines changed Original file line number Diff line number Diff line change 1- This happens when an Objective-C block captures both ` self ` and ` weakSelf ` , a
2- weak pointer to ` self ` . Possibly the developer meant to capture only ` weakSelf `
3- to avoid a retain cycle, but made a typo and used ` self ` as well in the block,
1+ This check reports an issue when an Objective-C block captures both ` self ` and ` weakSelf ` , a weak pointer to ` self ` .
2+ Possibly the developer meant to capture only ` weakSelf ` to avoid a retain cycle, but made a typo and used ` self `
43instead of ` strongSelf ` . In this case, this could cause a retain cycle.
4+
5+ Example:
6+
7+ ``` objectivec
8+ __weak __typeof (self) weakSelf = self;
9+ int (^my_block)() = ^() {
10+ __ strong __ typeof(weakSelf) strongSelf = weakSelf;
11+ if (strongSelf) {
12+ [ strongSelf foo] ;
13+ int x = self->x; // typo here
14+ }
15+ return 0;
16+ };
17+ ```
18+
19+ **Action**: Fixing the typo is generally the right course of action.
20+
21+ *Limitations:* To keep this check simple and intra-procedural, we rely on names to find `weakSelf`:
22+ we assume that any captured weak pointer whose name contains "self" is a weak reference to `self`.
Original file line number Diff line number Diff line change @@ -1459,11 +1459,29 @@ As explained by the analysis.
14591459
14601460Reported as "Mixed Self WeakSelf" by [ self-in-block] ( /docs/next/checker-self-in-block ) .
14611461
1462- This happens when an Objective-C block captures both ` self ` and ` weakSelf ` , a
1463- weak pointer to ` self ` . Possibly the developer meant to capture only ` weakSelf `
1464- to avoid a retain cycle, but made a typo and used ` self ` as well in the block,
1462+ This check reports an issue when an Objective-C block captures both ` self ` and ` weakSelf ` , a weak pointer to ` self ` .
1463+ Possibly the developer meant to capture only ` weakSelf ` to avoid a retain cycle, but made a typo and used ` self `
14651464instead of ` strongSelf ` . In this case, this could cause a retain cycle.
14661465
1466+ Example:
1467+
1468+ ``` objectivec
1469+ __weak __typeof (self) weakSelf = self;
1470+ int (^my_block)() = ^() {
1471+ __ strong __ typeof(weakSelf) strongSelf = weakSelf;
1472+ if (strongSelf) {
1473+ [ strongSelf foo] ;
1474+ int x = self->x; // typo here
1475+ }
1476+ return 0;
1477+ };
1478+ ```
1479+
1480+ **Action**: Fixing the typo is generally the right course of action.
1481+
1482+ *Limitations:* To keep this check simple and intra-procedural, we rely on names to find `weakSelf`:
1483+ we assume that any captured weak pointer whose name contains "self" is a weak reference to `self`.
1484+
14671485## MODIFIES_IMMUTABLE
14681486
14691487Reported as "Modifies Immutable" by [impurity](/docs/next/checker-impurity).
You can’t perform that action at this time.
0 commit comments