Skip to content

Commit 59d436f

Browse files
committed
Better support destructors in objcImpl
1 parent 0a34ab2 commit 59d436f

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

lib/AST/Decl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5361,8 +5361,10 @@ synthesizeEmptyFunctionBody(AbstractFunctionDecl *afd, void *context) {
53615361

53625362
DestructorDecl *
53635363
GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
5364+
auto dc = CD->getImplementationContext();
5365+
53645366
auto &ctx = CD->getASTContext();
5365-
auto *DD = new (ctx) DestructorDecl(CD->getLoc(), CD);
5367+
auto *DD = new (ctx) DestructorDecl(CD->getLoc(), dc->getAsGenericContext());
53665368

53675369
DD->setImplicit();
53685370

lib/AST/NameLookupRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Optional<DestructorDecl *> GetDestructorRequest::getCachedResult() const {
219219

220220
void GetDestructorRequest::cacheResult(DestructorDecl *value) const {
221221
auto *classDecl = std::get<0>(getStorage());
222-
classDecl->addMember(value);
222+
classDecl->getImplementationContext()->addMember(value);
223223
}
224224

225225
//----------------------------------------------------------------------------//

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ static void checkDynamicSelfType(ValueDecl *decl, Type type) {
12361236
/// checking whether it shadows an imported declaration).
12371237
static void checkObjCImplementationMemberAvoidsVTable(ValueDecl *VD) {
12381238
// We check the properties instead of their accessors.
1239-
if (isa<AccessorDecl>(VD))
1239+
if (isa<AccessorDecl>(VD) || isa<DestructorDecl>(member))
12401240
return;
12411241

12421242
// Are we in an @_objcImplementation extension?
@@ -3744,7 +3744,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
37443744
// Only check again for destructor decl outside of a class if our destructor
37453745
// is not marked as invalid.
37463746
if (!DD->isInvalid()) {
3747-
auto *nom = dyn_cast<NominalTypeDecl>(DD->getDeclContext());
3747+
auto *nom = dyn_cast<NominalTypeDecl>(
3748+
DD->getDeclContext()->getImplementedObjCContext());
37483749
if (!nom || (!isa<ClassDecl>(nom) && !nom->isMoveOnly())) {
37493750
DD->diagnose(diag::destructor_decl_outside_class_or_noncopyable);
37503751
}

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,8 +4657,8 @@ class DeclDeserializer {
46574657

46584658
dtor->setGenericSignature(MF.getGenericSignature(genericSigID));
46594659

4660-
dtor->setAccess(std::max(cast<NominalTypeDecl>(DC)->getFormalAccess(),
4661-
AccessLevel::Internal));
4660+
auto *nom = cast<NominalTypeDecl>(DC->getImplementedObjCContext());
4661+
dtor->setAccess(std::max(nom->getFormalAccess(), AccessLevel::Internal));
46624662

46634663
if (isImplicit)
46644664
dtor->setImplicit();

0 commit comments

Comments
 (0)