@@ -414,7 +414,7 @@ void RequirementFailure::emitRequirementNote(const Decl *anchor, Type lhs,
414
414
}
415
415
416
416
bool MissingConformanceFailure::diagnoseAsError () {
417
- auto * anchor = castToExpr ( getAnchor () );
417
+ auto anchor = getAnchor ();
418
418
auto nonConformingType = getLHS ();
419
419
auto protocolType = getRHS ();
420
420
@@ -423,8 +423,9 @@ bool MissingConformanceFailure::diagnoseAsError() {
423
423
// with it and if so skip conformance error, otherwise we'd
424
424
// produce an unrelated `<type> doesn't conform to Equatable protocol`
425
425
// 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))) {
428
429
auto *caseExpr = binaryOp->getArg ()->getElement (0 );
429
430
430
431
llvm::SmallPtrSet<Expr *, 4 > anchors;
@@ -452,6 +453,7 @@ bool MissingConformanceFailure::diagnoseAsError() {
452
453
// says that conformances for enums with associated values can't be
453
454
// synthesized.
454
455
if (isStandardComparisonOperator (anchor)) {
456
+ auto *expr = castToExpr (anchor);
455
457
auto isEnumWithAssociatedValues = [](Type type) -> bool {
456
458
if (auto *enumType = type->getAs <EnumType>())
457
459
return !enumType->getDecl ()->hasOnlyCasesWithoutAssociatedValues ();
@@ -464,7 +466,7 @@ bool MissingConformanceFailure::diagnoseAsError() {
464
466
(protocol->isSpecificProtocol (KnownProtocolKind::Equatable) ||
465
467
protocol->isSpecificProtocol (KnownProtocolKind::Comparable))) {
466
468
if (RequirementFailure::diagnoseAsError ()) {
467
- auto opName = getOperatorName (anchor );
469
+ auto opName = getOperatorName (expr );
468
470
emitDiagnostic (diag::no_binary_op_overload_for_enum_with_payload,
469
471
opName->str ());
470
472
return true ;
@@ -4998,8 +5000,15 @@ bool MissingGenericArgumentsFailure::diagnoseAsError() {
4998
5000
scopedParameters[base].push_back (GP);
4999
5001
});
5000
5002
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
+ }
5003
5012
5004
5013
bool diagnosed = false ;
5005
5014
for (const auto &scope : scopedParameters)
0 commit comments