Skip to content

Commit

Permalink
Merge pull request #31869 from gregomni/sr12759
Browse files Browse the repository at this point in the history
[QoI, Crasher] Don't include type variables in missing generic requirement match info
  • Loading branch information
CodaFi committed May 20, 2020
2 parents c230622 + d764fe8 commit 3939786
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
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
}
}


0 comments on commit 3939786

Please sign in to comment.