Skip to content

[QoI, Crasher] Don't include type variables in missing generic requirement match info #31869

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
merged 2 commits into from
May 20, 2020
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
15 changes: 12 additions & 3 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,8 @@ static const RequirementEnvironment &getOrCreateRequirementEnvironment(
}

static Optional<RequirementMatch> findMissingGenericRequirementForSolutionFix(
constraints::ConstraintFix *fix, ValueDecl *witness,
ProtocolConformance *conformance,
constraints::Solution &solution, constraints::ConstraintFix *fix,
ValueDecl *witness, ProtocolConformance *conformance,
const RequirementEnvironment &reqEnvironment) {
Type type, missingType;
RequirementKind requirementKind;
Expand Down Expand Up @@ -785,6 +785,15 @@ static Optional<RequirementMatch> findMissingGenericRequirementForSolutionFix(
return Optional<RequirementMatch>();
}

type = solution.simplifyType(type);
missingType = solution.simplifyType(missingType);

missingType = missingType->mapTypeOutOfContext();
if (missingType->hasTypeParameter())
if (auto env = conformance->getGenericEnvironment())
if (auto assocType = env->mapTypeIntoContext(missingType))
missingType = assocType;

auto missingRequirementMatch = [&](Type type) -> RequirementMatch {
Requirement requirement(requirementKind, type, missingType);
return RequirementMatch(witness, MatchKind::MissingRequirement,
Expand Down Expand Up @@ -986,7 +995,7 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
if (solution && conformance && solution->Fixes.size()) {
for (auto fix : solution->Fixes) {
if (auto result = findMissingGenericRequirementForSolutionFix(
fix, witness, conformance, reqEnvironment))
*solution, fix, witness, conformance, reqEnvironment))
return *result;
}
}
Expand Down
28 changes: 28 additions & 0 deletions test/decl/protocol/req/missing_conformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,31 @@ struct S3 : P12 { // expected-error {{type 'S3' does not conform to protocol 'P1
// expected-note@-1 {{candidate can not infer 'A' = 'P11' because 'P11' is not a nominal type and so can't conform to 'P11'}}
}

// SR-12759
struct CountSteps1<T> : Collection {
init(count: Int) { self.count = count }
var count: Int

var startIndex: Int { 0 }
var endIndex: Int { count }
func index(after i: Int) -> Int {
totalSteps += 1 // expected-error {{cannot find 'totalSteps' in scope}}
return i + 1
}
subscript(i: Int) -> Int { return i }
}

extension CountSteps1 // expected-error {{type 'CountSteps1<T>' does not conform to protocol 'RandomAccessCollection'}}
// expected-error@-1 {{conditional conformance of type 'CountSteps1<T>' to protocol 'RandomAccessCollection' does not imply conformance to inherited protocol 'BidirectionalCollection'}}
// expected-note@-2 {{did you mean to explicitly state the conformance like 'extension CountSteps1: BidirectionalCollection where ...'?}}
// expected-error@-3 {{type 'CountSteps1<T>' does not conform to protocol 'BidirectionalCollection'}}
: RandomAccessCollection
where T : Equatable
{
typealias Index = Int
func index(_ i: Index, offsetBy d: Int) -> Index {
return i + d
}
}