@@ -3572,58 +3572,45 @@ void AttributeChecker::visitTypeEraserAttr(TypeEraserAttr *attr) {
35723572void AttributeChecker::visitImplementsAttr (ImplementsAttr *attr) {
35733573 DeclContext *DC = D->getDeclContext ();
35743574
3575- Type T = attr->getProtocolType ();
3576- if (!T && attr->getProtocolTypeRepr ()) {
3577- auto context = TypeResolverContext::GenericRequirement;
3578- T = TypeResolution::resolveContextualType (attr->getProtocolTypeRepr (), DC,
3579- TypeResolutionOptions (context),
3580- /* unboundTyOpener*/ nullptr ,
3581- /* placeholderHandler*/ nullptr ,
3582- /* packElementOpener*/ nullptr );
3583- }
3584-
3585- // Definite error-types were already diagnosed in resolveType.
3586- if (T->hasError ())
3575+ ProtocolDecl *PD = attr->getProtocol (DC);
3576+
3577+ if (!PD) {
3578+ diagnose (attr->getLocation (), diag::implements_attr_non_protocol_type)
3579+ .highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
35873580 return ;
3588- attr-> setProtocolType (T);
3581+ }
35893582
3590- // Check that we got a ProtocolType.
3591- if (auto PT = T->getAs <ProtocolType>()) {
3592- ProtocolDecl *PD = PT->getDecl ();
3583+ // Check that the ProtocolType has the specified member.
3584+ LookupResult R =
3585+ TypeChecker::lookupMember (PD->getDeclContext (),
3586+ PD->getDeclaredInterfaceType (),
3587+ DeclNameRef (attr->getMemberName ()));
3588+ if (!R) {
3589+ diagnose (attr->getLocation (),
3590+ diag::implements_attr_protocol_lacks_member,
3591+ PD->getName (), attr->getMemberName ())
3592+ .highlight (attr->getMemberNameLoc ().getSourceRange ());
3593+ return ;
3594+ }
35933595
3594- // Check that the ProtocolType has the specified member.
3595- LookupResult R =
3596- TypeChecker::lookupMember (PD-> getDeclContext (), PT,
3597- DeclNameRef (attr-> getMemberName ()));
3598- if (!R ) {
3596+ // Check that the decl we're decorating is a member of a type that actually
3597+ // conforms to the specified protocol.
3598+ NominalTypeDecl *NTD = DC-> getSelfNominalTypeDecl ();
3599+ if ( auto *OtherPD = dyn_cast<ProtocolDecl>(NTD)) {
3600+ if (!OtherPD-> inheritsFrom (PD) ) {
35993601 diagnose (attr->getLocation (),
3600- diag::implements_attr_protocol_lacks_member,
3601- PD->getName (), attr->getMemberName ())
3602- .highlight (attr->getMemberNameLoc ().getSourceRange ());
3603- }
3604-
3605- // Check that the decl we're decorating is a member of a type that actually
3606- // conforms to the specified protocol.
3607- NominalTypeDecl *NTD = DC->getSelfNominalTypeDecl ();
3608- if (auto *OtherPD = dyn_cast<ProtocolDecl>(NTD)) {
3609- if (!OtherPD->inheritsFrom (PD)) {
3610- diagnose (attr->getLocation (),
3611- diag::implements_attr_protocol_not_conformed_to,
3612- NTD->getName (), PD->getName ())
3613- .highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
3614- }
3615- } else {
3616- SmallVector<ProtocolConformance *, 2 > conformances;
3617- if (!NTD->lookupConformance (PD, conformances)) {
3618- diagnose (attr->getLocation (),
3619- diag::implements_attr_protocol_not_conformed_to,
3620- NTD->getName (), PD->getName ())
3621- .highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
3622- }
3602+ diag::implements_attr_protocol_not_conformed_to,
3603+ NTD->getName (), PD->getName ())
3604+ .highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
36233605 }
36243606 } else {
3625- diagnose (attr->getLocation (), diag::implements_attr_non_protocol_type)
3626- .highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
3607+ SmallVector<ProtocolConformance *, 2 > conformances;
3608+ if (!NTD->lookupConformance (PD, conformances)) {
3609+ diagnose (attr->getLocation (),
3610+ diag::implements_attr_protocol_not_conformed_to,
3611+ NTD->getName (), PD->getName ())
3612+ .highlight (attr->getProtocolTypeRepr ()->getSourceRange ());
3613+ }
36273614 }
36283615}
36293616
0 commit comments