Merge pull request #70635 from DougGregor/async-sequence-typed-throws

Adopt typed throws in AsyncIteratorProtocol and AsyncSequence
This commit is contained in:
Doug Gregor
2024-01-29 11:51:25 -08:00
committed by GitHub
52 changed files with 1314 additions and 89 deletions

View File

@@ -10705,15 +10705,16 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
// Handle `next` reference.
if (getContextualTypePurpose(baseExpr) == CTP_ForEachSequence &&
isRefTo(memberRef, ctx.Id_next, /*labels=*/{})) {
(isRefTo(memberRef, ctx.Id_next, /*labels=*/{}) ||
isRefTo(memberRef, ctx.Id_next, /*labels=*/{StringRef()}))) {
auto *iteratorProto = cast<ProtocolDecl>(
getContextualType(baseExpr, /*forConstraint=*/false)
->getAnyNominal());
bool isAsync = iteratorProto->getKnownProtocolKind() ==
KnownProtocolKind::AsyncIteratorProtocol;
auto *next =
isAsync ? ctx.getAsyncIteratorNext() : ctx.getIteratorNext();
auto loc = locator->getAnchor().getStartLoc();
auto *next = TypeChecker::getForEachIteratorNextFunction(DC, loc, isAsync);
return simplifyValueWitnessConstraint(
ConstraintKind::ValueWitness, baseTy, next, memberTy, useDC,
@@ -10931,7 +10932,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
if (auto *base = dyn_cast<DeclRefExpr>(UDE->getBase())) {
if (auto var = dyn_cast_or_null<VarDecl>(base->getDecl())) {
if (var->getNameStr().contains("$generator") &&
UDE->getName().getBaseIdentifier() == Context.Id_next)
(UDE->getName().getBaseIdentifier() == Context.Id_next))
return success();
}
}