@@ -828,7 +828,20 @@ namespace {
828
828
829
829
Type firstArgTy = argTupleTy->getElement (0 ).getType ()->getWithoutParens ();
830
830
Type secondArgTy = argTupleTy->getElement (1 ).getType ()->getWithoutParens ();
831
-
831
+
832
+ auto isOptionalWithMatchingObjectType = [](Type optional,
833
+ Type object) -> bool {
834
+ if (auto objTy = optional->getRValueType ()->getOptionalObjectType ())
835
+ return objTy->getRValueType ()->isEqual (object->getRValueType ());
836
+
837
+ return false ;
838
+ };
839
+
840
+ auto isPotentialForcingOpportunity = [&](Type first, Type second) -> bool {
841
+ return isOptionalWithMatchingObjectType (first, second) ||
842
+ isOptionalWithMatchingObjectType (second, first);
843
+ };
844
+
832
845
// Determine whether the given declaration is favored.
833
846
auto isFavoredDecl = [&](ValueDecl *value) -> bool {
834
847
auto valueTy = value->getInterfaceType ();
@@ -882,14 +895,14 @@ namespace {
882
895
883
896
auto resultTy = fnTy->getResult ();
884
897
auto contextualTy = CS.getContextualType (expr);
885
-
886
- return
887
- ( isFavoredParamAndArg (CS, firstParamTy, firstArg, firstArgTy,
888
- secondArgTy) ||
889
- isFavoredParamAndArg (CS, secondParamTy, secondArg, secondArgTy,
890
- firstArgTy) ) &&
891
- firstParamTy-> isEqual (secondParamTy ) &&
892
- (!contextualTy || contextualTy->isEqual (resultTy));
898
+
899
+ return ( isFavoredParamAndArg (CS, firstParamTy, firstArg, firstArgTy,
900
+ secondArgTy) ||
901
+ isFavoredParamAndArg (CS, secondParamTy, secondArg, secondArgTy,
902
+ firstArgTy)) &&
903
+ firstParamTy-> isEqual (secondParamTy ) &&
904
+ ! isPotentialForcingOpportunity (firstArgTy, secondArgTy ) &&
905
+ (!contextualTy || contextualTy->isEqual (resultTy));
893
906
};
894
907
895
908
favorCallOverloads (expr, CS, isFavoredDecl);
0 commit comments