Skip to content

Commit 63ac80b

Browse files
authored
Merge pull request #59786 from slavapestov/associated-type-inference-protocol-extension-fix
Sema: Check conditional requirements in inferTypeWitnessesViaValueWitnesses()
2 parents b9907c6 + 4473363 commit 63ac80b

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
211211
// so won't be affected by whatever answer inference comes up with.
212212
auto *module = dc->getParentModule();
213213
auto checkConformance = [&](ProtocolDecl *proto) {
214-
auto otherConf = module->lookupConformance(conformance->getType(),
215-
proto);
216-
return (otherConf && otherConf.getConditionalRequirements().empty());
214+
auto typeInContext = dc->mapTypeIntoContext(conformance->getType());
215+
auto otherConf = TypeChecker::conformsToProtocol(
216+
typeInContext, proto, module);
217+
return !otherConf.isInvalid();
217218
};
218219

219220
// First check the extended protocol itself.
@@ -249,8 +250,10 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
249250
// type can't use it regardless of what associated types we end up
250251
// inferring, skip the witness.
251252
if (auto extension = dyn_cast<ExtensionDecl>(witness->getDeclContext()))
252-
if (!isExtensionUsableForInference(extension))
253+
if (!isExtensionUsableForInference(extension)) {
254+
LLVM_DEBUG(llvm::dbgs() << "Extension not usable for inference\n");
253255
continue;
256+
}
254257

255258
// Try to resolve the type witness via this value witness.
256259
auto witnessResult = inferTypeWitnessesViaValueWitness(req, witness);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P {
4+
associatedtype Body: P
5+
var body: Body { get }
6+
}
7+
8+
// The S: P conformance should pick up 'var body'
9+
// from 'extension PP'.
10+
struct S<T> {}
11+
extension S : P, PP where T : P {}
12+
13+
protocol PP : P {}
14+
extension PP {
15+
var body: Never { fatalError() }
16+
}
17+
18+
extension Never : PP {}

test/decl/protocol/req/missing_conformance.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ struct S5: P14 { // expected-error {{type 'S5' does not conform to protocol 'P14
129129
}
130130

131131
// SR-12759
132+
133+
// Note: the conformance to collection should succeed
132134
struct CountSteps1<T> : Collection {
133135
init(count: Int) { self.count = count }
134136
var count: Int

0 commit comments

Comments
 (0)