Skip to content

Commit 7c7caa2

Browse files
committed
Sema: Fix regression with 'Failure' type witness inference hack
We have a special hack to infer the 'Failure' type witness in 'AsyncIteratorProtocol' by considering the type of 'next()' witness. In eaf06ea I added a check to fix some assertions that could happen if 'next()' was witnessed by a declaration in a protocol extension or superclass, which has a different generic signature. However my check was too narrow, because it also prohibited this form of inference when 'next()' was in a different extension of the same nominal type. Allow this again. Fixes #79367. Fixes rdar://problem/145341658.
1 parent ff14828 commit 7c7caa2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,11 @@ AssociatedTypeInference::computeFailureTypeWitness(
24962496
if (!isAsyncIteratorProtocolNext(witness.first))
24972497
continue;
24982498

2499-
if (!witness.second || witness.second->getDeclContext() != dc)
2499+
// Different extensions of the same nominal are OK, but if the witness is in
2500+
// a protocol extension or a superclass or something, give up.
2501+
if (!witness.second ||
2502+
witness.second->getDeclContext()->getSelfNominalTypeDecl()
2503+
!= dc->getSelfNominalTypeDecl())
25002504
continue;
25012505

25022506
if (auto witnessFunc = dyn_cast<AbstractFunctionDecl>(witness.second)) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// https://github.com/swiftlang/swift/issues/79367
4+
5+
// 'Failure' type witness inference should still take place when
6+
// the 'next()' witness is in a different extension than the
7+
// conformance.
8+
9+
struct AsyncIteratorImpl<Element>: AsyncIteratorProtocol {}
10+
11+
extension AsyncIteratorImpl {
12+
func next() async throws -> Element? {
13+
fatalError()
14+
}
15+
}

0 commit comments

Comments
 (0)