File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -2426,13 +2426,17 @@ AssociatedTypeInference::computeFailureTypeWitness(
2426
2426
for (const auto &witness : valueWitnesses) {
2427
2427
if (isAsyncIteratorProtocolNext (witness.first )) {
2428
2428
if (auto witnessFunc = dyn_cast<AbstractFunctionDecl>(witness.second )) {
2429
+ auto thrownError = witnessFunc->getEffectiveThrownErrorType ();
2430
+
2429
2431
// If it doesn't throw, Failure == Never.
2430
- if (!witnessFunc-> hasThrows () )
2432
+ if (!thrownError )
2431
2433
return AbstractTypeWitness (assocType, ctx.getNeverType ());
2432
2434
2433
- // If it isn't 'rethrows', Failure == any Error.
2434
- if (!witnessFunc->getAttrs ().hasAttribute <RethrowsAttr>())
2435
- return AbstractTypeWitness (assocType, ctx.getErrorExistentialType ());
2435
+ // If it isn't 'rethrows', use the thrown error type;.
2436
+ if (!witnessFunc->getAttrs ().hasAttribute <RethrowsAttr>()) {
2437
+ return AbstractTypeWitness (assocType,
2438
+ dc->mapTypeIntoContext (*thrownError));
2439
+ }
2436
2440
2437
2441
for (auto req : witnessFunc->getGenericSignature ().getRequirements ()) {
2438
2442
if (req.getKind () == RequirementKind::Conformance) {
Original file line number Diff line number Diff line change @@ -51,3 +51,27 @@ extension InheritsAsyncSequence {
51
51
try await self . reduce ( into: [ Element] ( ) ) { $0. append ( $1) }
52
52
}
53
53
}
54
+
55
+ // Ensure that we can get the thrown error type from next().
56
+ struct Data { }
57
+
58
+ struct ErrorSequence < Element, Failure: Error > : AsyncSequence , AsyncIteratorProtocol {
59
+ let throwError : Failure
60
+
61
+ func makeAsyncIterator( ) -> ErrorSequence < Element , Failure > {
62
+ self
63
+ }
64
+
65
+ mutating func next( ) async throws ( Failure) -> Element ? {
66
+ throw throwError
67
+ }
68
+ }
69
+
70
+ enum MyError : Error {
71
+ case foo
72
+ }
73
+
74
+
75
+ func getASequence( ) -> any AsyncSequence < Data , MyError > {
76
+ return ErrorSequence < Data , _ > ( throwError: MyError . foo) // ERROR: Cannot convert return expression of type 'any Error' to return type 'MyError'
77
+ }
You can’t perform that action at this time.
0 commit comments