@@ -417,16 +417,18 @@ static bool paramIsIUO(const ValueDecl *decl, int paramNum) {
417417// / "Specialized" is essentially a form of subtyping, defined below.
418418static bool isDeclAsSpecializedAs (DeclContext *dc, ValueDecl *decl1,
419419 ValueDecl *decl2,
420- bool isDynamicOverloadComparison = false ) {
420+ bool isDynamicOverloadComparison = false ,
421+ bool allowMissingConformances = true ) {
421422 return evaluateOrDefault (decl1->getASTContext ().evaluator ,
422423 CompareDeclSpecializationRequest{
423- dc, decl1, decl2, isDynamicOverloadComparison},
424+ dc, decl1, decl2, isDynamicOverloadComparison,
425+ allowMissingConformances},
424426 false );
425427}
426428
427429bool CompareDeclSpecializationRequest::evaluate (
428430 Evaluator &eval, DeclContext *dc, ValueDecl *decl1, ValueDecl *decl2,
429- bool isDynamicOverloadComparison) const {
431+ bool isDynamicOverloadComparison, bool allowMissingConformances ) const {
430432 auto &C = decl1->getASTContext ();
431433 // Construct a constraint system to compare the two declarations.
432434 ConstraintSystem cs (dc, ConstraintSystemOptions ());
@@ -759,9 +761,16 @@ bool CompareDeclSpecializationRequest::evaluate(
759761 // Solve the system.
760762 auto solution = cs.solveSingle (FreeTypeVariableBinding::Allow);
761763
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+ }
765774 }
766775
767776 // If the first function has fewer effective parameters than the
@@ -1121,12 +1130,14 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
11211130 bool firstAsSpecializedAs = false ;
11221131 bool secondAsSpecializedAs = false ;
11231132 if (isDeclAsSpecializedAs (cs.DC , decl1, decl2,
1124- isDynamicOverloadComparison)) {
1133+ isDynamicOverloadComparison,
1134+ /* allowMissingConformances=*/ false )) {
11251135 score1 += weight;
11261136 firstAsSpecializedAs = true ;
11271137 }
11281138 if (isDeclAsSpecializedAs (cs.DC , decl2, decl1,
1129- isDynamicOverloadComparison)) {
1139+ isDynamicOverloadComparison,
1140+ /* allowMissingConformances=*/ false )) {
11301141 score2 += weight;
11311142 secondAsSpecializedAs = true ;
11321143 }
0 commit comments