Skip to content

Commit 39455d3

Browse files
committed
[WIP] Fix @_objcImpl initialization issue
TODO: Write tests for correct use of direct access in init/deinit/accessors, and correct use of dynamic access elsewhere.
1 parent 97bf476 commit 39455d3

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/AST/Decl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3749,10 +3749,13 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
37493749
bool forConformance,
37503750
bool includeInlineable,
37513751
llvm::function_ref<AccessLevel()> getAccessLevel) {
3752-
// If this is an @_objcImplementation member implementation, unconditionally
3753-
// forbid access. Name lookups will instead find and use the matching
3754-
// interface decl.
3755-
if (isObjCMemberImplementation(VD, getAccessLevel))
3752+
// If this is an @_objcImplementation member implementation, and we aren't in
3753+
// a context where we would access its storage directly, forbid access. Name
3754+
// lookups will instead find and use the matching interface decl.
3755+
// FIXME: Passing `true` for `isAccessOnSelf` may cause false positives.
3756+
if (isObjCMemberImplementation(VD, getAccessLevel) &&
3757+
VD->getAccessSemanticsFromContext(useDC, /*isAccessOnSelf=*/true)
3758+
!= AccessSemantics::DirectToStorage)
37563759
return false;
37573760

37583761
if (VD->getASTContext().isAccessControlDisabled())

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ InitKindRequest::evaluate(Evaluator &evaluator, ConstructorDecl *decl) const {
448448
// (or the same file) to add vtable entries, we can re-evaluate this
449449
// restriction.
450450
if (!decl->isSynthesized() &&
451-
isa<ExtensionDecl>(decl->getDeclContext()) &&
451+
isa<ExtensionDecl>(decl->getDeclContext()->getImplementedObjCContext()) &&
452452
!(decl->getAttrs().hasAttribute<DynamicReplacementAttr>())) {
453453

454454
if (classDcl->getForeignClassKind() == ClassDecl::ForeignKind::CFType) {

0 commit comments

Comments
 (0)