Sema: Your monthly dose of minor @objc fixes

- Disallow @objc on members of non-@objc protocols (the
  real reason for this patch)

- Add a separate diagnostic for @objc appearing on members
  in non-class, non-protocol types.

- Clean up the code that enforces that @objc can only be
  applied to @objc-rooted classes. The diagnostic would
  be incorrectly emitted for @objc subclasses of generic
  classes.

Fixes <rdar://problem/17273524>.

Swift SVN r31303
This commit is contained in:
Slava Pestov
2015-08-18 18:52:51 +00:00
parent ab70e9b554
commit af1e0b316e
6 changed files with 103 additions and 106 deletions

View File

@@ -2259,7 +2259,7 @@ ObjCClassKind ClassDecl::checkObjCAncestry() const {
bool genericAncestry = false, isObjC = false;
const ClassDecl *CD = this;
while (CD) {
for (;;) {
// If we hit circularity, we will diagnose at some point in typeCheckDecl().
// However we have to explicitly guard against that here because we get
// called as part of validateDecl().
@@ -2272,17 +2272,18 @@ ObjCClassKind ClassDecl::checkObjCAncestry() const {
if (CD->isObjC())
isObjC = true;
const ClassDecl *superclassDecl = nullptr;
if (CD->hasSuperclass())
superclassDecl = CD->getSuperclass()->getClassOrBoundGenericClass();
CD = superclassDecl;
if (!CD->hasSuperclass())
break;
CD = CD->getSuperclass()->getClassOrBoundGenericClass();
}
if (!isObjC)
return ObjCClassKind::NonObjC;
if (genericAncestry)
return ObjCClassKind::ObjCMembers;
if (CD == this || !CD->isObjC())
return ObjCClassKind::ObjCWithSwiftRoot;
return ObjCClassKind::ObjC;
}