Skip to content

Commit 2520d40

Browse files
committed
[CSOptimizer] Allow literal inference inside of operator chains
This is helpful in situations when all of the chained operators have literal arguments because it would make sure that every operator has the same score if there is no contextual type.
1 parent 479e61b commit 2520d40

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ inferTypeFromInitializerResultType(ConstraintSystem &cs,
450450
return {instanceTy, /*hasFailable=*/false};
451451
}
452452

453-
/// If the given expression represents a chain of operators that only have
453+
/// If the given expression represents a chain of operators that have
454454
/// only literals as arguments, attempt to deduce a potential type of the
455455
/// chain. For example if chain has only integral literals it's going to
456456
/// be `Int`, if there are some floating-point literals mixed in - it's going
@@ -1007,13 +1007,9 @@ static void determineBestChoicesInContext(
10071007
if (typeVar->getImpl().isFunctionResult()) {
10081008
auto *resultLoc = typeVar->getImpl().getLocator();
10091009

1010-
// We don't want to try and infer parts of operator
1011-
// chains.
1012-
if (!isOperator) {
1013-
if (auto type = inferTypeOfArithmeticOperatorChain(
1014-
cs.DC, resultLoc->getAnchor())) {
1015-
types.push_back({type, /*fromLiteral=*/true});
1016-
}
1010+
if (auto type = inferTypeOfArithmeticOperatorChain(
1011+
cs.DC, resultLoc->getAnchor())) {
1012+
types.push_back({type, /*fromLiteral=*/true});
10171013
}
10181014

10191015
auto binding =

0 commit comments

Comments
 (0)