@@ -213,14 +213,6 @@ namespace {
213213 }
214214
215215 if (auto *binaryExpr = dyn_cast<BinaryExpr>(expr)) {
216- if (auto *overload = dyn_cast<OverloadedDeclRefExpr>(binaryExpr->getFn ())) {
217- // Don't walk into nil coalescing operators. Attempting to favor
218- // based on operand types is wrong for this operator.
219- auto identifier = overload->getDecls ().front ()->getBaseIdentifier ();
220- if (identifier.isNilCoalescingOperator ())
221- return { false , expr };
222- }
223-
224216 LTI.binaryExprs .push_back (dyn_cast<BinaryExpr>(expr));
225217 }
226218
@@ -292,11 +284,25 @@ namespace {
292284
293285 // / For a given expression, given information that is global to the
294286 // / expression, attempt to derive a favored type for it.
295- bool computeFavoredTypeForExpr (Expr *expr, ConstraintSystem &CS) {
287+ void computeFavoredTypeForExpr (Expr *expr, ConstraintSystem &CS) {
296288 LinkedTypeInfo lti;
297289
298290 expr->walk (LinkedExprAnalyzer (lti, CS));
299291
292+ // Check whether we can proceed with favoring.
293+ if (llvm::any_of (lti.binaryExprs , [](const BinaryExpr *op) {
294+ auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(op->getFn ());
295+ if (!ODRE)
296+ return false ;
297+
298+ // Attempting to favor based on operand types is wrong for
299+ // nil-coalescing operator.
300+ auto identifier = ODRE->getDecls ().front ()->getBaseIdentifier ();
301+ return identifier.isNilCoalescingOperator ();
302+ })) {
303+ return ;
304+ }
305+
300306 if (lti.collectedTypes .size () == 1 ) {
301307 // TODO: Compute the BCT.
302308
@@ -371,13 +377,9 @@ namespace {
371377 };
372378
373379 simplifyBinOpExprTyVars ();
374-
375- return true ;
376380 }
377-
378- return false ;
379381 }
380-
382+
381383 // / Determine whether the given parameter type and argument should be
382384 // / "favored" because they match exactly.
383385 bool isFavoredParamAndArg (ConstraintSystem &CS, Type paramTy, Type argTy,
0 commit comments