Skip to content

Commit 1323953

Browse files
committed
Sema: Try not to make a negative impact
1 parent b0303bb commit 1323953

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,13 +1045,15 @@ struct Score {
10451045
friend Score operator-(const Score &x, const Score &y) {
10461046
Score result;
10471047
for (unsigned i = 0; i != NumScoreKinds; ++i) {
1048+
ASSERT(x.Data[i] >= y.Data[i]);
10481049
result.Data[i] = x.Data[i] - y.Data[i];
10491050
}
10501051
return result;
10511052
}
10521053

10531054
friend Score &operator-=(Score &x, const Score &y) {
10541055
for (unsigned i = 0; i != NumScoreKinds; ++i) {
1056+
ASSERT(x.Data[i] >= y.Data[i]);
10551057
x.Data[i] -= y.Data[i];
10561058
}
10571059
return x;

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15032,9 +15032,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1503215032
SmallVector<Type, 4> unwraps2;
1503315033
type2->lookThroughAllOptionalTypes(unwraps2);
1503415034

15035-
auto impact = unwraps1.size() != unwraps2.size()
15036-
? unwraps1.size() - unwraps2.size()
15037-
: 1;
15035+
unsigned impact = 1;
15036+
if (unwraps1.size() > unwraps2.size())
15037+
impact = unwraps1.size() - unwraps2.size();
15038+
else if (unwraps2.size() > unwraps1.size())
15039+
impact = unwraps2.size() - unwraps1.size();
15040+
1503815041
return recordFix(fix, impact) ? SolutionKind::Error : SolutionKind::Solved;
1503915042
}
1504015043

0 commit comments

Comments
 (0)