Skip to content

Commit 59cb282

Browse files
committed
[Sema] Add assertion to diagnoseImplicitSelfUseInClosure
The only cases where we don't have a closure type here should now be for implicit expressions and macro expansions. Eventually we ought to stop doing `typeCheckExpression` in CSApply entirely, which would eliminate this special case.
1 parent 9ba3523 commit 59cb282

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,11 +2524,25 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
25242524
AbstractClosureExpr *ACE = nullptr;
25252525
if (DC->isLocalContext()) {
25262526
while (DC->getParent()->isLocalContext() && !ACE) {
2527-
// FIXME: This is happening too early, because closure->getType() isn't set.
2528-
if (auto *closure = dyn_cast<AbstractClosureExpr>(DC))
2529-
if (closure->getType())
2527+
if (auto *closure = dyn_cast<AbstractClosureExpr>(DC)) {
2528+
// FIXME: We have a couple of calls to typeCheckExpression remaining in
2529+
// CSApply that can result in running this logic before the solution has
2530+
// been applied to the parent expression. This should only happen for
2531+
// implicit code and macro expansions though.
2532+
auto isInGeneratedBuffer = [&]() -> bool {
2533+
auto loc = E->getStartLoc();
2534+
if (!loc)
2535+
return false;
2536+
auto buffer = ctx.SourceMgr.findBufferContainingLoc(loc);
2537+
return ctx.SourceMgr.hasGeneratedSourceInfo(buffer);
2538+
};
2539+
DEBUG_ASSERT(closure->getType() || E->isImplicit() ||
2540+
isInGeneratedBuffer());
2541+
if (closure->getType()) {
25302542
if (DiagnoseWalker::isClosureRequiringSelfQualification(closure))
25312543
ACE = const_cast<AbstractClosureExpr *>(closure);
2544+
}
2545+
}
25322546
DC = DC->getParent();
25332547
}
25342548
}

0 commit comments

Comments
 (0)