@@ -4479,12 +4479,13 @@ combineBaseNameAndFirstArgument(Identifier baseName,
4479
4479
// / Compute the scope between two potentially-matching names, which is
4480
4480
// / effectively the sum of the edit distances between the corresponding
4481
4481
// / argument labels.
4482
- static unsigned scorePotentiallyMatchingNames (DeclName lhs, DeclName rhs,
4483
- bool isFunc,
4484
- unsigned limit) {
4482
+ static Optional<unsigned > scorePotentiallyMatchingNames (DeclName lhs,
4483
+ DeclName rhs,
4484
+ bool isFunc,
4485
+ unsigned limit) {
4485
4486
// If there are a different number of argument labels, we're done.
4486
4487
if (lhs.getArgumentNames ().size () != rhs.getArgumentNames ().size ())
4487
- return limit ;
4488
+ return None ;
4488
4489
4489
4490
// Score the base name match. If there is a first argument for a
4490
4491
// function, include its text along with the base name's text.
@@ -4506,14 +4507,14 @@ static unsigned scorePotentiallyMatchingNames(DeclName lhs, DeclName rhs,
4506
4507
4507
4508
score = lhsFirstName.edit_distance (rhsFirstName.str (), true , limit);
4508
4509
}
4509
- if (score >= limit) return limit ;
4510
+ if (score > limit) return None ;
4510
4511
4511
4512
// Compute the edit distance between matching argument names.
4512
4513
for (unsigned i = isFunc ? 1 : 0 ; i < lhs.getArgumentNames ().size (); ++i) {
4513
4514
score += scoreIdentifiers (lhs.getArgumentNames ()[i],
4514
4515
rhs.getArgumentNames ()[i],
4515
4516
limit - score);
4516
- if (score >= limit) return limit ;
4517
+ if (score > limit) return None ;
4517
4518
}
4518
4519
4519
4520
return score;
@@ -4532,8 +4533,10 @@ static Optional<DeclName> omitNeedlessWords(TypeChecker &tc, ValueDecl *value) {
4532
4533
}
4533
4534
4534
4535
// / Determine the score between two potentially-matching declarations.
4535
- static unsigned scorePotentiallyMatching (TypeChecker &tc, ValueDecl *req,
4536
- ValueDecl *witness, unsigned limit) {
4536
+ static Optional<unsigned > scorePotentiallyMatching (TypeChecker &tc,
4537
+ ValueDecl *req,
4538
+ ValueDecl *witness,
4539
+ unsigned limit) {
4537
4540
DeclName reqName = req->getFullName ();
4538
4541
DeclName witnessName = witness->getFullName ();
4539
4542
@@ -4663,12 +4666,12 @@ static bool shouldWarnAboutPotentialWitness(ValueDecl *req,
4663
4666
}
4664
4667
4665
4668
// If the score is relatively high, don't warn: this is probably
4666
- // unrelated. Allow about one typo for every two properly-typed
4669
+ // unrelated. Allow about one typo for every four properly-typed
4667
4670
// characters, which prevents completely-wacky suggestions in many
4668
4671
// cases.
4669
4672
unsigned reqNameLen = getNameLength (req->getFullName ());
4670
4673
unsigned witnessNameLen = getNameLength (witness->getFullName ());
4671
- if (score > (std::min (reqNameLen, witnessNameLen) + 1 ) / 3 )
4674
+ if (score > (std::min (reqNameLen, witnessNameLen)) / 4 )
4672
4675
return false ;
4673
4676
4674
4677
return true ;
@@ -4878,16 +4881,17 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
4878
4881
4879
4882
// Score this particular optional requirement.
4880
4883
auto score = scorePotentiallyMatching (*this , req, value, bestScore);
4884
+ if (!score) continue ;
4881
4885
4882
4886
// If the score is better than the best we've seen, update the best
4883
4887
// and clear out the list.
4884
- if (score < bestScore) {
4888
+ if (* score < bestScore) {
4885
4889
bestOptionalReqs.clear ();
4886
- bestScore = score;
4890
+ bestScore = * score;
4887
4891
}
4888
4892
4889
4893
// If this score matches the (possible new) best score, record it.
4890
- if (score == bestScore && bestScore < UINT_MAX )
4894
+ if (* score == bestScore)
4891
4895
bestOptionalReqs.push_back (req);
4892
4896
}
4893
4897
0 commit comments