Skip to content

Commit af65c0e

Browse files
committed
[Diagnostics] Prioritize contextual type mismatch other ambiguities
1 parent 5437622 commit af65c0e

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,14 +2904,11 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
29042904

29052905
// Collect aggregated fixes from all solutions
29062906
llvm::SmallMapVector<std::pair<ConstraintLocator *, FixKind>,
2907-
llvm::SmallVector<ConstraintFix *, 4>, 4> aggregatedFixes;
2908-
for (const auto &solution: solutions) {
2909-
for (auto fixesPerLocator: solution.getAggregatedFixes()) {
2910-
for (auto kindAndFixes: fixesPerLocator.second) {
2911-
aggregatedFixes[{fixesPerLocator.first, kindAndFixes.first}]
2912-
.push_back(kindAndFixes.second.front());
2913-
}
2914-
}
2907+
llvm::TinyPtrVector<ConstraintFix *>, 4>
2908+
aggregatedFixes;
2909+
for (const auto &solution : solutions) {
2910+
for (auto *fix : solution.Fixes)
2911+
aggregatedFixes[{fix->getLocator(), fix->getKind()}].push_back(fix);
29152912
}
29162913

29172914
// If there is an overload difference, let's see if there's a common callee
@@ -2964,20 +2961,17 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
29642961
auto &DE = getASTContext().Diags;
29652962
auto name = decl->getFullName();
29662963

2967-
if (name.isOperator()) {
2968-
diagnoseOperatorAmbiguity(*this, name.getBaseIdentifier(), solutions,
2969-
commonCalleeLocator);
2970-
return true;
2971-
}
2972-
29732964
// Emit an error message for the ambiguity.
29742965
if (aggregatedFixes.size() == 1 &&
2975-
aggregatedFixes.front().first.first
2976-
->getLastElementAs<LocatorPathElt::ContextualType>()) {
2966+
aggregatedFixes.front().first.first->isForContextualType()) {
29772967
auto *anchor = aggregatedFixes.front().first.first->getAnchor();
29782968
auto baseName = name.getBaseName();
29792969
DE.diagnose(commonAnchor->getLoc(), diag::no_candidates_match_result_type,
29802970
baseName.userFacingName(), getContextualType(anchor));
2971+
} else if (name.isOperator()) {
2972+
diagnoseOperatorAmbiguity(*this, name.getBaseIdentifier(), solutions,
2973+
commonCalleeLocator);
2974+
return true;
29812975
} else {
29822976
bool isApplication = llvm::find_if(ArgumentInfos, [&](const auto argInfo) {
29832977
return argInfo.first->getAnchor() == commonAnchor;

0 commit comments

Comments
 (0)