Skip to content

Support overrides of unavailable inits in objcImpl #69290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/Sema/TypeCheckDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2948,14 +2948,21 @@ class ObjCImplementationChecker {
void addRequirements(IterableDeclContext *idc) {
assert(idc->getDecl()->hasClangNode());
for (Decl *_member : idc->getMembers()) {
// Skip accessors; we'll match their storage instead. Also skip overrides;
// the override checker handles those.
// Skip accessors; we'll match their storage instead.
auto member = dyn_cast<ValueDecl>(_member);
if (!member || isa<AccessorDecl>(member) || member->getOverriddenDecl())
if (!member || isa<AccessorDecl>(member))
continue;

ASTContext &ctx = member->getASTContext();

// Also skip overrides, unless they override an unavailable decl, which
// makes them not formally overrides anymore.
if (member->getOverriddenDecl() &&
!member->getOverriddenDecl()->getAttrs().isUnavailable(ctx))
continue;

// Skip alternate Swift names for other language modes.
if (member->getAttrs().isUnavailable(member->getASTContext()))
if (member->getAttrs().isUnavailable(ctx))
continue;

// Skip async versions of members. We'll match against the completion
Expand Down
7 changes: 7 additions & 0 deletions test/decl/ext/Inputs/objc_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@interface ObjCBaseClass

- (instancetype)init __attribute__((unavailable));

// Need two initializers to reproduce certain conflict bugs.
- (instancetype)initFromSuperclass:(int)param __attribute__((objc_designated_initializer));
Expand Down Expand Up @@ -161,6 +162,12 @@

@end

@interface ObjCBasicInitClass : ObjCBaseClass

- (nonnull instancetype)init __attribute__((objc_designated_initializer));

@end



struct ObjCStruct {
Expand Down
6 changes: 6 additions & 0 deletions test/decl/ext/objc_implementation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ protocol EmptySwiftProto {}
}
}

@_objcImplementation extension ObjCBasicInitClass {
init() {
// OK
}
}

@_objcImplementation extension ObjCClass {}
// expected-error@-1 {{duplicate implementation of Objective-C class 'ObjCClass'}}

Expand Down