Skip to content

Sema: Check conditional requirements in inferTypeWitnessesViaValueWitnesses() [5.7] #59794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/Sema/TypeCheckProtocolInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
// so won't be affected by whatever answer inference comes up with.
auto *module = dc->getParentModule();
auto checkConformance = [&](ProtocolDecl *proto) {
auto otherConf = module->lookupConformance(conformance->getType(),
proto);
return (otherConf && otherConf.getConditionalRequirements().empty());
auto typeInContext = dc->mapTypeIntoContext(conformance->getType());
auto otherConf = TypeChecker::conformsToProtocol(
typeInContext, proto, module);
return !otherConf.isInvalid();
};

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

// Try to resolve the type witness via this value witness.
auto witnessResult = inferTypeWitnessesViaValueWitness(req, witness);
Expand Down
18 changes: 18 additions & 0 deletions test/decl/protocol/req/associated_type_protocol_extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %target-typecheck-verify-swift

protocol P {
associatedtype Body: P
var body: Body { get }
}

// The S: P conformance should pick up 'var body'
// from 'extension PP'.
struct S<T> {}
extension S : P, PP where T : P {}

protocol PP : P {}
extension PP {
var body: Never { fatalError() }
}

extension Never : PP {}
2 changes: 2 additions & 0 deletions test/decl/protocol/req/missing_conformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ struct S5: P14 { // expected-error {{type 'S5' does not conform to protocol 'P14
}

// SR-12759

// Note: the conformance to collection should succeed
struct CountSteps1<T> : Collection {
init(count: Int) { self.count = count }
var count: Int
Expand Down