mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user