Skip to content

Commit 367b112

Browse files
committed
Fix last test failure
1 parent 0f33636 commit 367b112

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,13 +1520,20 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
15201520
if (!ty->hasReferenceSemantics())
15211521
return false;
15221522

1523-
// If this is a `AbstractFunctionDecl` (`FuncDecl`, `ConstructorDecl`, or `DestructorDecl`.
1524-
// `@autoclosure @escaping () -> String = String()` as one example),
1525-
// then the capture is fine.
1523+
// If this is an implicit self parameter to a `AbstractFunctionDecl`
1524+
// (`FuncDecl`, `ConstructorDecl`, or `DestructorDecl`,
1525+
// `@autoclosure @escaping () -> String = String()` as one example)
1526+
// then it isn't actually capturing the closure's 'self', and is fine.
15261527
if (isa<AbstractFunctionDecl>(DRE->getDecl())) {
15271528
return false;
15281529
}
15291530

1531+
// If this decl isn't named "self", then it isn't an implicit self capture
1532+
// and we have no reason to reject it.
1533+
if (!DRE->getDecl()->getBaseName().getIdentifier().is("self")) {
1534+
return false;
1535+
}
1536+
15301537
auto isExplicitWeakSelfCapture = false;
15311538
if (auto closureExpr = dyn_cast<ClosureExpr>(inClosure)) {
15321539
if (auto selfDecl = closureExpr->getCapturedSelfDecl()) {

0 commit comments

Comments
 (0)