@@ -513,7 +513,10 @@ bool MissingConformanceFailure::diagnoseAsError() {
513513 llvm::SmallPtrSet<Expr *, 4 > anchors;
514514 for (const auto *fix : getSolution ().Fixes ) {
515515 if (auto anchor = fix->getAnchor ()) {
516- if (anchor.is <Expr *>())
516+ auto path = fix->getLocator ()->getPath ();
517+ SourceRange range;
518+ simplifyLocator (anchor, path, range);
519+ if (anchor && anchor.is <Expr *>())
517520 anchors.insert (getAsExpr (anchor));
518521 }
519522 }
@@ -654,10 +657,15 @@ bool MissingConformanceFailure::diagnoseAsAmbiguousOperatorRef() {
654657 if (!ODRE)
655658 return false ;
656659
660+ auto isStandardType = [](Type ty) {
661+ return ty->isStdlibType () || ty->is <TupleType>();
662+ };
663+
657664 auto name = ODRE->getDecls ().front ()->getBaseName ();
658- if (!(name.isOperator () && getLHS ()->isStdlibType () && getRHS ()->isStdlibType ()))
665+ if (!(name.isOperator () && isStandardType (getLHS ()) &&
666+ isStandardType (getRHS ()))) {
659667 return false ;
660-
668+ }
661669 // If this is an operator reference and both types are from stdlib,
662670 // let's produce a generic diagnostic about invocation and a note
663671 // about missing conformance just in case.
@@ -2448,9 +2456,6 @@ bool ContextualFailure::diagnoseAsError() {
24482456 return false ;
24492457 }
24502458
2451- if (diagnoseExtraneousAssociatedValues ())
2452- return true ;
2453-
24542459 // Special case of some common conversions involving Swift.String
24552460 // indexes, catching cases where people attempt to index them with an integer.
24562461 if (isIntegerToStringIndexConversion ()) {
@@ -2891,24 +2896,6 @@ void ContextualFailure::tryFixIts(InFlightDiagnostic &diagnostic) const {
28912896 return ;
28922897}
28932898
2894- bool ContextualFailure::diagnoseExtraneousAssociatedValues () const {
2895- if (auto match =
2896- getLocator ()->getLastElementAs <LocatorPathElt::PatternMatch>()) {
2897- if (auto enumElementPattern =
2898- dyn_cast<EnumElementPattern>(match->getPattern ())) {
2899- emitDiagnosticAt (enumElementPattern->getNameLoc (),
2900- diag::enum_element_pattern_assoc_values_mismatch,
2901- enumElementPattern->getName ());
2902- emitDiagnosticAt (enumElementPattern->getNameLoc (),
2903- diag::enum_element_pattern_assoc_values_remove)
2904- .fixItRemove (enumElementPattern->getSubPattern ()->getSourceRange ());
2905- return true ;
2906- }
2907- }
2908-
2909- return false ;
2910- }
2911-
29122899bool ContextualFailure::diagnoseCoercionToUnrelatedType () const {
29132900 auto anchor = getRawAnchor ();
29142901 auto *coerceExpr = getAsExpr<CoerceExpr>(anchor);
@@ -8684,6 +8671,19 @@ bool TupleLabelMismatchWarning::diagnoseAsError() {
86848671 return true ;
86858672}
86868673
8674+ bool AssociatedValueMismatchFailure::diagnoseAsError () {
8675+ auto match = getLocator ()->castLastElementTo <LocatorPathElt::PatternMatch>();
8676+ auto *enumElementPattern = dyn_cast<EnumElementPattern>(match.getPattern ());
8677+
8678+ emitDiagnosticAt (enumElementPattern->getNameLoc (),
8679+ diag::enum_element_pattern_assoc_values_mismatch,
8680+ enumElementPattern->getName ());
8681+ emitDiagnosticAt (enumElementPattern->getNameLoc (),
8682+ diag::enum_element_pattern_assoc_values_remove)
8683+ .fixItRemove (enumElementPattern->getSubPattern ()->getSourceRange ());
8684+ return true ;
8685+ }
8686+
86878687bool SwiftToCPointerConversionInInvalidContext::diagnoseAsError () {
86888688 auto argInfo = getFunctionArgApplyInfo (getLocator ());
86898689 if (!argInfo)
0 commit comments