@@ -3306,14 +3306,22 @@ void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) {
3306
3306
// Check that the decl we're decorating is a member of a type that actually
3307
3307
// conforms to the specified protocol.
3308
3308
NominalTypeDecl *NTD = DC->getSelfNominalTypeDecl ();
3309
- SmallVector<ProtocolConformance *, 2 > conformances;
3310
- if (!NTD->lookupConformance (PD, conformances)) {
3311
- diagnose (attr->getLocation (),
3312
- diag::implements_attr_protocol_not_conformed_to,
3313
- NTD->getName (), PD->getName ())
3314
- .highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
3309
+ if (auto *OtherPD = dyn_cast<ProtocolDecl>(NTD)) {
3310
+ if (!OtherPD->inheritsFrom (PD)) {
3311
+ diagnose (attr->getLocation (),
3312
+ diag::implements_attr_protocol_not_conformed_to,
3313
+ NTD->getName (), PD->getName ())
3314
+ .highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
3315
+ }
3316
+ } else {
3317
+ SmallVector<ProtocolConformance *, 2 > conformances;
3318
+ if (!NTD->lookupConformance (PD, conformances)) {
3319
+ diagnose (attr->getLocation (),
3320
+ diag::implements_attr_protocol_not_conformed_to,
3321
+ NTD->getName (), PD->getName ())
3322
+ .highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
3323
+ }
3315
3324
}
3316
-
3317
3325
} else {
3318
3326
diagnose (attr->getLocation (), diag::implements_attr_non_protocol_type)
3319
3327
.highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
0 commit comments