[CS] A couple of minor improvements to operator diagnostics

- Simplify the fix locator when looking for a
fix already present in a pattern match, this
avoids us emitting both a diagnostic for the
argument conversion, and for a conformance failure.
- Include tuples in the diagnostic logic where
we emit a generic "operator cannot be applied"
diagnostic, as a conformance diagnostic is
unlikely to be helpful in that case.
This commit is contained in:
Hamish Knight
2023-05-04 14:36:16 +01:00
parent b5e9bbb68d
commit 68075696eb
4 changed files with 14 additions and 14 deletions

View File

@@ -513,7 +513,10 @@ bool MissingConformanceFailure::diagnoseAsError() {
llvm::SmallPtrSet<Expr *, 4> anchors;
for (const auto *fix : getSolution().Fixes) {
if (auto anchor = fix->getAnchor()) {
if (anchor.is<Expr *>())
auto path = fix->getLocator()->getPath();
SourceRange range;
simplifyLocator(anchor, path, range);
if (anchor && anchor.is<Expr *>())
anchors.insert(getAsExpr(anchor));
}
}
@@ -654,10 +657,15 @@ bool MissingConformanceFailure::diagnoseAsAmbiguousOperatorRef() {
if (!ODRE)
return false;
auto name = ODRE->getDecls().front()->getBaseName();
if (!(name.isOperator() && getLHS()->isStdlibType() && getRHS()->isStdlibType()))
return false;
auto isStandardType = [](Type ty) {
return ty->isStdlibType() || ty->is<TupleType>();
};
auto name = ODRE->getDecls().front()->getBaseName();
if (!(name.isOperator() && isStandardType(getLHS()) &&
isStandardType(getRHS()))) {
return false;
}
// If this is an operator reference and both types are from stdlib,
// let's produce a generic diagnostic about invocation and a note
// about missing conformance just in case.