@@ -414,7 +414,7 @@ void RequirementFailure::emitRequirementNote(const Decl *anchor, Type lhs,
414414}
415415
416416bool MissingConformanceFailure::diagnoseAsError () {
417- auto * anchor = castToExpr ( getAnchor () );
417+ auto anchor = getAnchor ();
418418 auto nonConformingType = getLHS ();
419419 auto protocolType = getRHS ();
420420
@@ -423,8 +423,9 @@ bool MissingConformanceFailure::diagnoseAsError() {
423423 // with it and if so skip conformance error, otherwise we'd
424424 // produce an unrelated `<type> doesn't conform to Equatable protocol`
425425 // diagnostic.
426- if (isPatternMatchingOperator (const_cast <Expr *>(anchor))) {
427- if (auto *binaryOp = dyn_cast_or_null<BinaryExpr>(findParentExpr (anchor))) {
426+ if (isPatternMatchingOperator (anchor)) {
427+ auto *expr = castToExpr (anchor);
428+ if (auto *binaryOp = dyn_cast_or_null<BinaryExpr>(findParentExpr (expr))) {
428429 auto *caseExpr = binaryOp->getArg ()->getElement (0 );
429430
430431 llvm::SmallPtrSet<Expr *, 4 > anchors;
@@ -452,6 +453,7 @@ bool MissingConformanceFailure::diagnoseAsError() {
452453 // says that conformances for enums with associated values can't be
453454 // synthesized.
454455 if (isStandardComparisonOperator (anchor)) {
456+ auto *expr = castToExpr (anchor);
455457 auto isEnumWithAssociatedValues = [](Type type) -> bool {
456458 if (auto *enumType = type->getAs <EnumType>())
457459 return !enumType->getDecl ()->hasOnlyCasesWithoutAssociatedValues ();
@@ -464,7 +466,7 @@ bool MissingConformanceFailure::diagnoseAsError() {
464466 (protocol->isSpecificProtocol (KnownProtocolKind::Equatable) ||
465467 protocol->isSpecificProtocol (KnownProtocolKind::Comparable))) {
466468 if (RequirementFailure::diagnoseAsError ()) {
467- auto opName = getOperatorName (anchor );
469+ auto opName = getOperatorName (expr );
468470 emitDiagnostic (diag::no_binary_op_overload_for_enum_with_payload,
469471 opName->str ());
470472 return true ;
@@ -4998,8 +5000,15 @@ bool MissingGenericArgumentsFailure::diagnoseAsError() {
49985000 scopedParameters[base].push_back (GP);
49995001 });
50005002
5001- if (!isScoped)
5002- return diagnoseForAnchor (castToExpr (getAnchor ()), Parameters);
5003+ // FIXME: this code should be generalized now that we can anchor the
5004+ // fixes on the TypeRepr with the missing generic arg.
5005+ if (!isScoped) {
5006+ assert (getAnchor ().is <Expr *>() || getAnchor ().is <TypeRepr *>());
5007+ if (auto *expr = getAsExpr (getAnchor ()))
5008+ return diagnoseForAnchor (expr, Parameters);
5009+
5010+ return diagnoseForAnchor (getAnchor ().get <TypeRepr *>(), Parameters);
5011+ }
50035012
50045013 bool diagnosed = false ;
50055014 for (const auto &scope : scopedParameters)
0 commit comments