Skip to content

Commit e8c4cd0

Browse files
committed
Correct logic for gating of @rethrows and adjust the determinates to be based upon throws and not rethrows spelling
1 parent 92229b6 commit e8c4cd0

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ ProtocolRethrowsRequirementsRequest::evaluate(Evaluator &evaluator,
778778
ASTContext &ctx = decl->getASTContext();
779779

780780
// only allow rethrowing requirements to be determined from marked protocols
781-
if (decl->getAttrs().hasAttribute<swift::AtRethrowsAttr>()) {
781+
if (!decl->getAttrs().hasAttribute<swift::AtRethrowsAttr>()) {
782782
return ProtocolRethrowsRequirementList(ctx.AllocateCopy(found));
783783
}
784784

@@ -789,7 +789,7 @@ ProtocolRethrowsRequirementsRequest::evaluate(Evaluator &evaluator,
789789
// it must have a rethrows attribute
790790
// it must not have any parameters that are closures that cause rethrowing
791791
if (!fnDecl ||
792-
!fnDecl->getAttrs().hasAttribute<RethrowsAttr>()) {
792+
!fnDecl->hasThrows()) {
793793
continue;
794794
}
795795

@@ -828,22 +828,25 @@ ProtocolRethrowsRequirementsRequest::evaluate(Evaluator &evaluator,
828828
FunctionRethrowingKind
829829
FunctionRethrowingKindRequest::evaluate(Evaluator &evaluator,
830830
AbstractFunctionDecl *decl) const {
831-
if (decl->getAttrs().hasAttribute<RethrowsAttr>()) {
832-
GenericSignature genericSig = decl->getGenericSignature();
833-
FunctionRethrowingKind kind = getParameterThrowingKind(decl, genericSig);
834-
// since we have checked all arguments, if we still havent found anything
835-
// check the self parameter
836-
if (kind == FunctionRethrowingKind::Invalid &&
837-
decl->hasImplicitSelfDecl()) {
838-
auto selfParam = decl->getImplicitSelfDecl();
839-
if (selfParam) {
840-
auto interfaceTy = selfParam->getInterfaceType();
841-
kind = getTypeThrowingKind(interfaceTy, genericSig);
831+
if (decl->hasThrows()) {
832+
if (auto proto = dyn_cast<ProtocolDecl>(decl->getDeclContext())) {
833+
if (proto->isRethrowingProtocol()) {
834+
GenericSignature genericSig = decl->getGenericSignature();
835+
FunctionRethrowingKind kind = getParameterThrowingKind(decl, genericSig);
836+
// since we have checked all arguments, if we still havent found anything
837+
// check the self parameter
838+
if (kind == FunctionRethrowingKind::Invalid &&
839+
decl->hasImplicitSelfDecl()) {
840+
auto selfParam = decl->getImplicitSelfDecl();
841+
if (selfParam) {
842+
auto interfaceTy = selfParam->getInterfaceType();
843+
kind = getTypeThrowingKind(interfaceTy, genericSig);
844+
}
845+
}
846+
847+
return kind;
842848
}
843849
}
844-
845-
return kind;
846-
} else if (decl->hasThrows()) {
847850
return FunctionRethrowingKind::Throws;
848851
}
849852
return FunctionRethrowingKind::None;

0 commit comments

Comments
 (0)