Skip to content

Commit 44ac39a

Browse files
committed
Diagnose unavailable closures without types
In complex situations, a type would not be assigned to an abstract closure that was the declaration context of the declaration being checked. This used to cause crashes because you couldn't query a closure on whether it was an async context if it didn't have a type assigned. This behaviour has been updated to lazily compute the function decl ext info if the type hasn't already been assigned. This means that calling `AbstractClosureExpr::isAsyncContext` is now safe, even when a type has not yet been assigned. The request change was added in commit c3b6160.
1 parent 974a6bd commit 44ac39a

File tree

1 file changed

+0
-28
lines changed

1 file changed

+0
-28
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,34 +3586,6 @@ bool ExprAvailabilityWalker::diagnoseDeclRefAvailability(
35863586
static bool
35873587
diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
35883588
const Expr *call, const ExportContext &Where) {
3589-
// FIXME: I don't think this is right, but I don't understand the issue well
3590-
// enough to fix it properly. If the decl context is an abstract
3591-
// closure, we need it to have a type assigned to it before we can
3592-
// determine whether it is an asynchronous context. It will crash
3593-
// when we go to check without one. In TypeChecker::typeCheckExpression
3594-
// (TypeCheckConstraints.cpp:403), we apply a solution before calling
3595-
// `performSyntacticDiagnosticsForTarget`, which eventually calls
3596-
// down to this function. Under most circumstances, the context that
3597-
// we're in is typechecked at that point and has a type assigned.
3598-
// When working with specific result builders, the solution applied
3599-
// results in an expression with an unset type. In these cases, the
3600-
// application makes its way into `ConstraintSystem::applySolution` for
3601-
// closures (CSClosure.cpp:1356). The type is computed, but is
3602-
// squirreled away in the constrain system to be applied once the
3603-
// checks (including this one) approve of the decls within the decl
3604-
// context before applying the type to the expression. It might be
3605-
// possible to drive the constraint solver through the availability
3606-
// checker and into us so that we can ask for it, but that feels wrong
3607-
// too.
3608-
// This behavior is demonstrated by the first use of the `tuplify`
3609-
// function in `testExistingPatternsInCaseStatements` in
3610-
// `test/Constraints/result_builder.swift`.
3611-
const AbstractClosureExpr *declCtxAsExpr =
3612-
dyn_cast<AbstractClosureExpr>(Where.getDeclContext());
3613-
if (declCtxAsExpr && !declCtxAsExpr->getType()) {
3614-
return false;
3615-
}
3616-
36173589
// If we are in a synchronous context, don't check it
36183590
if (!Where.getDeclContext()->isAsyncContext())
36193591
return false;

0 commit comments

Comments
 (0)