Skip to content

Commit 847a7d2

Browse files
Update comments
1 parent 598d470 commit 847a7d2

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

include/swift/AST/Stmt.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,6 @@ class alignas(1 << PatternAlignInBits) StmtConditionElement {
727727
/// or `let self = self` condition.
728728
/// - If `requiresCaptureListRef` is `true`, additionally requires that the
729729
/// 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`.
732730
bool rebindsSelf(ASTContext &Ctx, bool requiresCaptureListRef = false) const;
733731

734732
SourceLoc getStartLoc() const;
@@ -838,8 +836,6 @@ class LabeledConditionalStmt : public LabeledStmt {
838836
/// or `let self = self` condition.
839837
/// - If `requiresCaptureListRef` is `true`, additionally requires that the
840838
/// 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`.
843839
bool rebindsSelf(ASTContext &Ctx, bool requiresCaptureListRef = false) const;
844840

845841
static bool classof(const Stmt *S) {

lib/AST/Stmt.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,6 @@ void LabeledConditionalStmt::setCond(StmtCondition e) {
514514
/// or `let self = self` condition.
515515
/// - If `requiresCaptureListRef` is `true`, additionally requires that the
516516
/// 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`.
519517
bool LabeledConditionalStmt::rebindsSelf(ASTContext &Ctx,
520518
bool requiresCaptureListRef) const {
521519
return llvm::any_of(getCond(), [&Ctx, requiresCaptureListRef](const auto &cond) {
@@ -527,8 +525,6 @@ bool LabeledConditionalStmt::rebindsSelf(ASTContext &Ctx,
527525
/// or `let self = self` condition.
528526
/// - If `requiresCaptureListRef` is `true`, additionally requires that the
529527
/// 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`.
532528
bool StmtConditionElement::rebindsSelf(ASTContext &Ctx,
533529
bool requiresCaptureListRef) const {
534530
auto pattern = getPatternOrNull();

lib/Sema/MiscDiagnostics.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,13 +1748,22 @@ class ImplicitSelfUsageChecker : public BaseDiagnosticWalker {
17481748
return false;
17491749
}
17501750

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.
17521753
// This lets us reject invalid examples like:
17531754
//
1754-
// let `self` = self ?? .somethingElse
1755+
// var `self` = self ?? .somethingElse
17551756
// guard let self = self else { return }
17561757
// method() // <- implicit self is not allowed
17571758
//
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+
//
17581767
return conditionalStmt->rebindsSelf(Ctx, /*requiresCaptureListRef*/ true);
17591768
}
17601769

0 commit comments

Comments
 (0)