Skip to content

Commit bd56b46

Browse files
authored
Merge pull request #21336 from rudkx/rdar46687985
[ConstraintSystem] Better handling of operators with multiple designa…
2 parents d98b5d1 + 10ef734 commit bd56b46

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,11 +1670,18 @@ void ConstraintSystem::sortDesignatedTypes(
16701670
size_t nextType = 0;
16711671
for (auto argType : argInfo.getTypes()) {
16721672
auto *nominal = argType->getAnyNominal();
1673-
for (size_t i = nextType + 1; i < nominalTypes.size(); ++i) {
1673+
for (size_t i = nextType; i < nominalTypes.size(); ++i) {
16741674
if (nominal == nominalTypes[i]) {
16751675
std::swap(nominalTypes[nextType], nominalTypes[i]);
16761676
++nextType;
16771677
break;
1678+
} else if (auto *protoDecl = dyn_cast<ProtocolDecl>(nominalTypes[i])) {
1679+
if (TC.conformsToProtocol(argType, protoDecl, DC,
1680+
ConformanceCheckFlags::InExpression)) {
1681+
std::swap(nominalTypes[nextType], nominalTypes[i]);
1682+
++nextType;
1683+
break;
1684+
}
16781685
}
16791686
}
16801687
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1 -solver-enable-operator-designated-types
2+
3+
func test(_ d: Double) -> Double {
4+
return d + d - d - (d / 2) + (d / 2) + (d / 2.0)
5+
}

0 commit comments

Comments
 (0)