Skip to content

Commit 0598917

Browse files
committed
[CSFix] Implement coalescing for generic argument mismatch fixes
1 parent 17b09a8 commit 0598917

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

include/swift/Sema/CSFix.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,10 @@ class GenericArgumentsMismatch final
11001100
return {getTrailingObjects<unsigned>(), NumMismatches};
11011101
}
11021102

1103+
bool coalesceAndDiagnose(const Solution &solution,
1104+
ArrayRef<ConstraintFix *> secondaryFixes,
1105+
bool asNote = false) const override;
1106+
11031107
bool diagnose(const Solution &solution, bool asNote = false) const override;
11041108

11051109
static GenericArgumentsMismatch *create(ConstraintSystem &cs, Type actual,
@@ -1112,6 +1116,9 @@ class GenericArgumentsMismatch final
11121116
}
11131117

11141118
private:
1119+
bool diagnose(const Solution &solution, ArrayRef<unsigned> mismatches,
1120+
bool asNote = false) const;
1121+
11151122
MutableArrayRef<unsigned> getMismatchesBuf() {
11161123
return {getTrailingObjects<unsigned>(), NumMismatches};
11171124
}

lib/Sema/CSFix.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,31 @@ AllowFunctionTypeMismatch::create(ConstraintSystem &cs, Type lhs, Type rhs,
732732
AllowFunctionTypeMismatch(cs, lhs, rhs, locator, index);
733733
}
734734

735+
bool GenericArgumentsMismatch::coalesceAndDiagnose(
736+
const Solution &solution, ArrayRef<ConstraintFix *> secondaryFixes,
737+
bool asNote) const {
738+
std::set<unsigned> scratch(getMismatches().begin(), getMismatches().end());
739+
740+
for (auto *fix : secondaryFixes) {
741+
auto *genericArgsFix = fix->castTo<GenericArgumentsMismatch>();
742+
for (auto mismatchIdx : genericArgsFix->getMismatches())
743+
scratch.insert(mismatchIdx);
744+
}
745+
746+
SmallVector<unsigned> mismatches(scratch.begin(), scratch.end());
747+
return diagnose(solution, mismatches, asNote);
748+
}
749+
750+
bool GenericArgumentsMismatch::diagnose(const Solution &solution,
751+
bool asNote) const {
752+
return diagnose(solution, getMismatches(), asNote);
753+
}
754+
735755
bool GenericArgumentsMismatch::diagnose(const Solution &solution,
756+
ArrayRef<unsigned> mismatches,
736757
bool asNote) const {
737758
GenericArgumentsMismatchFailure failure(solution, getFromType(), getToType(),
738-
getMismatches(), getLocator());
759+
mismatches, getLocator());
739760
return failure.diagnose(asNote);
740761
}
741762

0 commit comments

Comments
 (0)