Skip to content

Commit c11beb5

Browse files
committed
Sema: Make wonky logic explicit in diagnoseImplicitSelfUseInClosure()
We walk up the DeclContext hierarchy looking for closures, but they might not have had their types set yet because they're currently being type checked.
1 parent 78d70ab commit c11beb5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,9 +1823,10 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
18231823

18241824
// If the closure's type was inferred to be noescape, then it doesn't
18251825
// need qualification.
1826-
if (AnyFunctionRef(const_cast<AbstractClosureExpr *>(CE))
1827-
.isKnownNoEscape())
1828-
return false;
1826+
if (auto funcTy = CE->getType()->getAs<FunctionType>()) {
1827+
if (funcTy->isNoEscape())
1828+
return false;
1829+
}
18291830

18301831
if (auto autoclosure = dyn_cast<AutoClosureExpr>(CE)) {
18311832
if (autoclosure->getThunkKind() == AutoClosureExpr::Kind::AsyncLet)
@@ -2094,9 +2095,11 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
20942095
AbstractClosureExpr *ACE = nullptr;
20952096
if (DC->isLocalContext()) {
20962097
while (DC->getParent()->isLocalContext() && !ACE) {
2098+
// FIXME: This is happening too early, because closure->getType() isn't set.
20972099
if (auto *closure = dyn_cast<AbstractClosureExpr>(DC))
2098-
if (DiagnoseWalker::isClosureRequiringSelfQualification(closure, ctx))
2099-
ACE = const_cast<AbstractClosureExpr *>(closure);
2100+
if (closure->getType())
2101+
if (DiagnoseWalker::isClosureRequiringSelfQualification(closure, ctx))
2102+
ACE = const_cast<AbstractClosureExpr *>(closure);
21002103
DC = DC->getParent();
21012104
}
21022105
}

0 commit comments

Comments
 (0)