File tree Expand file tree Collapse file tree 4 files changed +24
-7
lines changed
test/decl/protocol/conforms Expand file tree Collapse file tree 4 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -734,14 +734,9 @@ static Expr *removeErasureToExistentialError(Expr *expr) {
734
734
735
735
return expr;
736
736
}
737
+ }
737
738
738
- // / Determine whether the given function uses typed throws in a manner
739
- // / than is structurally similar to 'rethrows', e.g.,
740
- // /
741
- // / \code
742
- // / func map<T, E>(_ body: (Element) throws(E) -> T) throws(E) -> [T]
743
- // / \endcode
744
- static bool isRethrowLikeTypedThrows (AbstractFunctionDecl *func) {
739
+ bool swift::isRethrowLikeTypedThrows (AbstractFunctionDecl *func) {
745
740
// This notion is only for compatibility in Swift 5 and is disabled
746
741
// when FullTypedThrows is enabled.
747
742
ASTContext &ctx = func->getASTContext ();
@@ -788,6 +783,8 @@ static bool isRethrowLikeTypedThrows(AbstractFunctionDecl *func) {
788
783
return true ;
789
784
}
790
785
786
+ namespace {
787
+
791
788
// / Determine whether the given rethrows context is only allowed to be
792
789
// / rethrowing because of the historically-rethrowing behavior of
793
790
// / AsyncSequence and AsyncIteratorProtocol.
Original file line number Diff line number Diff line change @@ -45,6 +45,14 @@ enum class ThrownErrorSubtyping {
45
45
ThrownErrorSubtyping compareThrownErrorsForSubtyping (
46
46
Type subThrownError, Type superThrownError, DeclContext *dc);
47
47
48
+ // / Determine whether the given function uses typed throws in a manner
49
+ // / that is structurally similar to 'rethrows', e.g.,
50
+ // /
51
+ // / \code
52
+ // / func map<T, E>(_ body: (Element) throws(E) -> T) throws(E) -> [T]
53
+ // / \endcode
54
+ bool isRethrowLikeTypedThrows (AbstractFunctionDecl *func);
55
+
48
56
}
49
57
50
58
#endif // SWIFT_SEMA_TYPECHECKEFFECTS_H
Original file line number Diff line number Diff line change @@ -603,6 +603,11 @@ RequirementMatch swift::matchWitness(
603
603
}
604
604
605
605
case PolymorphicEffectKind::Always:
606
+ // If the witness is using typed throws in a manner that looks
607
+ // like rethrows, allow it.
608
+ if (isRethrowLikeTypedThrows (funcWitness))
609
+ break ;
610
+
606
611
return RequirementMatch (witness, MatchKind::RethrowsConflict);
607
612
}
608
613
}
Original file line number Diff line number Diff line change @@ -69,3 +69,10 @@ func testAssociatedTypes() {
69
69
func assocFailureType< T: FailureAssociatedType > ( _ value: T , _ error: T . Failure ) throws ( T. Failure) {
70
70
throw error
71
71
}
72
+
73
+ // Allow a typed-throws version of a function to witness a rethrowing function.
74
+ public protocol HasRethrowingMap : Sequence {
75
+ func map< T> ( _ transform: ( Element ) throws -> T ) rethrows -> [ T ]
76
+ }
77
+
78
+ extension Array : HasRethrowingMap { }
You can’t perform that action at this time.
0 commit comments