Skip to content

Commit 3a4215d

Browse files
authored
Merge pull request #80536 from slavapestov/fix-issue-79367-6.2
[6.2] Sema: Fix regression with 'Failure' type witness inference hack
2 parents cb444b6 + 69ebffb commit 3a4215d

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
@@ -2497,7 +2497,11 @@ AssociatedTypeInference::computeFailureTypeWitness(
24972497
if (!isAsyncIteratorProtocolNext(witness.first))
24982498
continue;
24992499

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

25032507
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)