Skip to content

Commit ebcc9c2

Browse files
committed
Revert "Disable SE-0365 behavior for escaping closues in Swift 5 mode"
This reverts commit f8ca293.
1 parent f8ca293 commit ebcc9c2

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,20 +1538,6 @@ static bool closureHasWeakSelfCapture(const AbstractClosureExpr *ACE) {
15381538
return false;
15391539
}
15401540

1541-
/// Whether or not this closure with a `weak self` capture is permitted
1542-
/// to use implicit self. We can't permit this for escaping closures in
1543-
/// Swift 5 mode, because the implicit self AST in Swift 5 would cause
1544-
/// self to be captured strongly instead of weakly.
1545-
static bool
1546-
allowsImplicitSelfForWeakSelfCapture(const AbstractClosureExpr *ACE) {
1547-
if (ACE->getASTContext().LangOpts.isSwiftVersionAtLeast(6)) {
1548-
return true;
1549-
}
1550-
1551-
return AnyFunctionRef(const_cast<AbstractClosureExpr *>(ACE))
1552-
.isKnownNoEscape();
1553-
}
1554-
15551541
/// Whether or not implicit self decls in this closure require manual
15561542
/// lookup in order to perform diagnostics with the semantics described
15571543
/// in SE-0365. This is necessary for closures that capture self weakly
@@ -1654,8 +1640,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
16541640
// let self = .someOptionalVariable else { return }` or `let self =
16551641
// someUnrelatedVariable`. If self hasn't been unwrapped yet and is still
16561642
// an optional, we would have already hit an error elsewhere.
1657-
if (closureHasWeakSelfCapture(inClosure) &&
1658-
allowsImplicitSelfForWeakSelfCapture(inClosure)) {
1643+
if (closureHasWeakSelfCapture(inClosure)) {
16591644
return !implicitWeakSelfReferenceIsValid(DRE, inClosure);
16601645
}
16611646

test/expr/closure/closures.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,21 +749,21 @@ public class TestImplicitSelfForWeakSelfCapture {
749749
doVoidStuff { [weak self] in
750750
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
751751
guard let self = self else { return }
752-
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
752+
method()
753753
}
754754

755755
doVoidStuff { [weak self] in
756756
guard let self else { return }
757-
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
757+
method()
758758
}
759759

760760
doVoidStuff { [weak self] in
761761
if let self = self {
762-
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
762+
method()
763763
}
764764

765765
if let self {
766-
method() // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
766+
method()
767767
}
768768
}
769769

0 commit comments

Comments
 (0)