File tree Expand file tree Collapse file tree 3 files changed +11
-10
lines changed Expand file tree Collapse file tree 3 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -727,8 +727,6 @@ class alignas(1 << PatternAlignInBits) StmtConditionElement {
727
727
// / or `let self = self` condition.
728
728
// / - If `requiresCaptureListRef` is `true`, additionally requires that the
729
729
// / RHS of the self condition references a var defined in a capture list.
730
- // / - If `requireLoadExpr` is `true`, additionally requires that the RHS of
731
- // / the self condition is a `LoadExpr`.
732
730
bool rebindsSelf (ASTContext &Ctx, bool requiresCaptureListRef = false ) const ;
733
731
734
732
SourceLoc getStartLoc () const ;
@@ -838,8 +836,6 @@ class LabeledConditionalStmt : public LabeledStmt {
838
836
// / or `let self = self` condition.
839
837
// / - If `requiresCaptureListRef` is `true`, additionally requires that the
840
838
// / RHS of the self condition references a var defined in a capture list.
841
- // / - If `requireLoadExpr` is `true`, additionally requires that the RHS of
842
- // / the self condition is a `LoadExpr`.
843
839
bool rebindsSelf (ASTContext &Ctx, bool requiresCaptureListRef = false ) const ;
844
840
845
841
static bool classof (const Stmt *S) {
Original file line number Diff line number Diff line change @@ -514,8 +514,6 @@ void LabeledConditionalStmt::setCond(StmtCondition e) {
514
514
// / or `let self = self` condition.
515
515
// / - If `requiresCaptureListRef` is `true`, additionally requires that the
516
516
// / RHS of the self condition references a var defined in a capture list.
517
- // / - If `requireLoadExpr` is `true`, additionally requires that the RHS of
518
- // / the self condition is a `LoadExpr`.
519
517
bool LabeledConditionalStmt::rebindsSelf (ASTContext &Ctx,
520
518
bool requiresCaptureListRef) const {
521
519
return llvm::any_of (getCond (), [&Ctx, requiresCaptureListRef](const auto &cond) {
@@ -527,8 +525,6 @@ bool LabeledConditionalStmt::rebindsSelf(ASTContext &Ctx,
527
525
// / or `let self = self` condition.
528
526
// / - If `requiresCaptureListRef` is `true`, additionally requires that the
529
527
// / RHS of the self condition references a var defined in a capture list.
530
- // / - If `requireLoadExpr` is `true`, additionally requires that the RHS of
531
- // / the self condition is a `LoadExpr`.
532
528
bool StmtConditionElement::rebindsSelf (ASTContext &Ctx,
533
529
bool requiresCaptureListRef) const {
534
530
auto pattern = getPatternOrNull ();
Original file line number Diff line number Diff line change @@ -1748,13 +1748,22 @@ class ImplicitSelfUsageChecker : public BaseDiagnosticWalker {
1748
1748
return false ;
1749
1749
}
1750
1750
1751
- // Require `LoadExpr`s when validating the self binding.
1751
+ // Require that the RHS of the `let self = self` condition
1752
+ // refers to a variable defined in a capture list.
1752
1753
// This lets us reject invalid examples like:
1753
1754
//
1754
- // let `self` = self ?? .somethingElse
1755
+ // var `self` = self ?? .somethingElse
1755
1756
// guard let self = self else { return }
1756
1757
// method() // <- implicit self is not allowed
1757
1758
//
1759
+ // In 5.10, instead of this check, compiler was checking that RHS of the
1760
+ // self binding is loaded from a mutable variable. This is incorrect, but
1761
+ // before SE-0481 compiler was trying to maintain this behavior in Swift 5
1762
+ // mode for source compatibility. After SE-0481 this does not work
1763
+ // anymore, because even in Swift 5 mode `weak self` capture is not mutable.
1764
+ // So we have to introduce a breaking change as part of the SE-0481, and use
1765
+ // proper check for capture list even in Swift 5 mode.
1766
+ //
1758
1767
return conditionalStmt->rebindsSelf (Ctx, /* requiresCaptureListRef*/ true );
1759
1768
}
1760
1769
You can’t perform that action at this time.
0 commit comments