@@ -3309,6 +3309,18 @@ bool RefactoringActionMemberwiseInitLocalRefactoring::performChange() {
3309
3309
return false ;
3310
3310
}
3311
3311
3312
+ // / If \p NTD is a protocol, return all the protocols it inherits from. If it's
3313
+ // / a type, return all the protocols it conforms to.
3314
+ static SmallVector<ProtocolDecl *, 2 > getAllProtocols (NominalTypeDecl *NTD) {
3315
+ if (auto Proto = dyn_cast<ProtocolDecl>(NTD)) {
3316
+ return SmallVector<ProtocolDecl *, 2 >(
3317
+ Proto->getInheritedProtocols ().begin (),
3318
+ Proto->getInheritedProtocols ().end ());
3319
+ } else {
3320
+ return NTD->getAllProtocols ();
3321
+ }
3322
+ }
3323
+
3312
3324
class AddEquatableContext {
3313
3325
3314
3326
// / Declaration context
@@ -3366,19 +3378,23 @@ class AddEquatableContext {
3366
3378
std::vector<VarDecl *> getUserAccessibleProperties ();
3367
3379
3368
3380
public:
3381
+ AddEquatableContext (NominalTypeDecl *Decl)
3382
+ : DC(Decl), Adopter(Decl->getDeclaredType ()),
3383
+ StartLoc(Decl->getBraces ().Start),
3384
+ ProtocolsLocations(Decl->getInherited ()),
3385
+ Protocols(getAllProtocols(Decl)),
3386
+ ProtInsertStartLoc(Decl->getNameLoc ()),
3387
+ StoredProperties(Decl->getStoredProperties ()),
3388
+ Range(Decl->getMembers ()){};
3369
3389
3370
- AddEquatableContext (NominalTypeDecl *Decl) : DC(Decl),
3371
- Adopter (Decl->getDeclaredType ()), StartLoc(Decl->getBraces ().Start),
3372
- ProtocolsLocations(Decl->getInherited ()),
3373
- Protocols(Decl->getAllProtocols ()), ProtInsertStartLoc(Decl->getNameLoc ()),
3374
- StoredProperties(Decl->getStoredProperties ()), Range(Decl->getMembers ()) {};
3375
-
3376
- AddEquatableContext (ExtensionDecl *Decl) : DC(Decl),
3377
- Adopter(Decl->getExtendedType ()), StartLoc(Decl->getBraces ().Start),
3378
- ProtocolsLocations(Decl->getInherited ()),
3379
- Protocols(Decl->getExtendedNominal ()->getAllProtocols()),
3380
- ProtInsertStartLoc(Decl->getExtendedTypeRepr ()->getEndLoc()),
3381
- StoredProperties(Decl->getExtendedNominal ()->getStoredProperties()), Range(Decl->getMembers ()) {};
3390
+ AddEquatableContext (ExtensionDecl *Decl)
3391
+ : DC(Decl), Adopter(Decl->getExtendedType ()),
3392
+ StartLoc(Decl->getBraces ().Start),
3393
+ ProtocolsLocations(Decl->getInherited ()),
3394
+ Protocols(getAllProtocols(Decl->getExtendedNominal ())),
3395
+ ProtInsertStartLoc(Decl->getExtendedTypeRepr ()->getEndLoc()),
3396
+ StoredProperties(Decl->getExtendedNominal ()->getStoredProperties()),
3397
+ Range(Decl->getMembers ()){};
3382
3398
3383
3399
AddEquatableContext () : DC(nullptr ), Adopter(), ProtocolsLocations(),
3384
3400
Protocols(), StoredProperties(), Range(nullptr , nullptr ) {};
@@ -3583,11 +3599,11 @@ class AddCodableContext {
3583
3599
public:
3584
3600
AddCodableContext (NominalTypeDecl *Decl)
3585
3601
: DC(Decl), StartLoc(Decl->getBraces ().Start),
3586
- Protocols(Decl-> getAllProtocols ()), Range(Decl->getMembers ()){};
3602
+ Protocols(getAllProtocols(Decl )), Range(Decl->getMembers ()){};
3587
3603
3588
3604
AddCodableContext (ExtensionDecl *Decl)
3589
3605
: DC(Decl), StartLoc(Decl->getBraces ().Start),
3590
- Protocols(Decl->getExtendedNominal ()->getAllProtocols( )),
3606
+ Protocols(getAllProtocols( Decl->getExtendedNominal ())),
3591
3607
Range(Decl->getMembers ()){};
3592
3608
3593
3609
AddCodableContext () : DC(nullptr ), Protocols(), Range(nullptr , nullptr ){};
0 commit comments