Skip to content

Commit 91c75a2

Browse files
authored
Merge pull request #69379 from DougGregor/typed-throws-convert-to-any-error
2 parents 1e5f69b + 6e0aeab commit 91c75a2

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,11 +2639,11 @@ InterfaceTypeRequest::evaluate(Evaluator &eval, ValueDecl *D) const {
26392639
Type thrownTy = AFD->getThrownInterfaceType();
26402640
if (thrownTy) {
26412641
thrownTy = AFD->getThrownInterfaceType();
2642-
ProtocolDecl *errorProto = Context.getErrorDecl();
2643-
if (thrownTy && errorProto) {
2642+
auto anyErrorType = Context.getErrorExistentialType();
2643+
if (thrownTy && anyErrorType) {
26442644
Type thrownTyInContext = AFD->mapTypeIntoContext(thrownTy);
2645-
if (!TypeChecker::conformsToProtocol(
2646-
thrownTyInContext, errorProto, AFD->getParentModule())) {
2645+
if (!TypeChecker::isConvertibleTo(
2646+
thrownTyInContext, anyErrorType, AFD)) {
26472647
SourceLoc loc;
26482648
if (auto thrownTypeRepr = AFD->getThrownTypeRepr())
26492649
loc = thrownTypeRepr->getLoc();

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,9 +3712,9 @@ NeverNullType TypeResolver::resolveASTFunctionType(
37123712
thrownTy = Type();
37133713
} else if (!options.contains(TypeResolutionFlags::SilenceErrors) &&
37143714
!thrownTy->hasTypeParameter() &&
3715-
!TypeChecker::conformsToProtocol(
3716-
thrownTy, ctx.getErrorDecl(),
3717-
resolution.getDeclContext()->getParentModule())) {
3715+
!TypeChecker::isConvertibleTo(
3716+
thrownTy, ctx.getErrorExistentialType(),
3717+
resolution.getDeclContext())) {
37183718
diagnoseInvalid(
37193719
thrownTypeRepr, thrownTypeRepr->getLoc(), diag::thrown_type_not_error,
37203720
thrownTy);

test/decl/func/typed_throws.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,5 @@ struct HasASubscript {
123123
}
124124
}
125125
}
126+
127+
func throwCodableErrors() throws(any Codable & Error) { }

0 commit comments

Comments
 (0)