@@ -417,16 +417,18 @@ static bool paramIsIUO(const ValueDecl *decl, int paramNum) {
417
417
// / "Specialized" is essentially a form of subtyping, defined below.
418
418
static bool isDeclAsSpecializedAs (DeclContext *dc, ValueDecl *decl1,
419
419
ValueDecl *decl2,
420
- bool isDynamicOverloadComparison = false ) {
420
+ bool isDynamicOverloadComparison = false ,
421
+ bool allowMissingConformances = true ) {
421
422
return evaluateOrDefault (decl1->getASTContext ().evaluator ,
422
423
CompareDeclSpecializationRequest{
423
- dc, decl1, decl2, isDynamicOverloadComparison},
424
+ dc, decl1, decl2, isDynamicOverloadComparison,
425
+ allowMissingConformances},
424
426
false );
425
427
}
426
428
427
429
bool CompareDeclSpecializationRequest::evaluate (
428
430
Evaluator &eval, DeclContext *dc, ValueDecl *decl1, ValueDecl *decl2,
429
- bool isDynamicOverloadComparison) const {
431
+ bool isDynamicOverloadComparison, bool allowMissingConformances ) const {
430
432
auto &C = decl1->getASTContext ();
431
433
// Construct a constraint system to compare the two declarations.
432
434
ConstraintSystem cs (dc, ConstraintSystemOptions ());
@@ -759,9 +761,16 @@ bool CompareDeclSpecializationRequest::evaluate(
759
761
// Solve the system.
760
762
auto solution = cs.solveSingle (FreeTypeVariableBinding::Allow);
761
763
762
- // Ban value-to-optional conversions.
763
- if (solution && solution->getFixedScore ().Data [SK_ValueToOptional] == 0 )
764
- return completeResult (true );
764
+ if (solution) {
765
+ auto score = solution->getFixedScore ();
766
+
767
+ // Ban value-to-optional conversions and
768
+ // missing conformances if they are disallowed.
769
+ if (score.Data [SK_ValueToOptional] == 0 &&
770
+ (allowMissingConformances ||
771
+ score.Data [SK_MissingSynthesizableConformance] == 0 ))
772
+ return completeResult (true );
773
+ }
765
774
}
766
775
767
776
// If the first function has fewer effective parameters than the
@@ -1121,12 +1130,14 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
1121
1130
bool firstAsSpecializedAs = false ;
1122
1131
bool secondAsSpecializedAs = false ;
1123
1132
if (isDeclAsSpecializedAs (cs.DC , decl1, decl2,
1124
- isDynamicOverloadComparison)) {
1133
+ isDynamicOverloadComparison,
1134
+ /* allowMissingConformances=*/ false )) {
1125
1135
score1 += weight;
1126
1136
firstAsSpecializedAs = true ;
1127
1137
}
1128
1138
if (isDeclAsSpecializedAs (cs.DC , decl2, decl1,
1129
- isDynamicOverloadComparison)) {
1139
+ isDynamicOverloadComparison,
1140
+ /* allowMissingConformances=*/ false )) {
1130
1141
score2 += weight;
1131
1142
secondAsSpecializedAs = true ;
1132
1143
}
0 commit comments