Diagnose redeclarations of Objective-C methods.

@objc methods, initializers, deinitializers, properties, and
subscripts all produce Objective-C methods. Diagnose cases where two
such entities (which may be of different kinds) produce the same
Objective-C method in the same class.

As a special exception, one can have an Objective-C method in an
extension that conflicts with an Objective-C method in the original
class definition, so long as the original class definition is from a
different model. This reflects the reality in Objective-C that the
category definition wins over the original definition, and is used in
at least one overlay (SpriteKit).

This is the first part of rdar://problem/18391046; the second part
involves checking that overrides are sane.

Swift SVN r23147
This commit is contained in:
Doug Gregor
2014-11-07 01:15:14 +00:00
parent e70ca2762d
commit 89e5e5b6fa
26 changed files with 671 additions and 179 deletions

View File

@@ -2996,7 +2996,7 @@ public:
}
};
class ObjCMemberLookupTable;
class ObjCMethodLookupTable;
/// ClassDecl - This is the declaration of a class, for example:
///
@@ -3007,10 +3007,10 @@ class ObjCMemberLookupTable;
class ClassDecl : public NominalTypeDecl {
SourceLoc ClassLoc;
Type Superclass;
ObjCMemberLookupTable *ObjCMemberLookup = nullptr;
ObjCMethodLookupTable *ObjCMethodLookup = nullptr;
/// Create the Objective-C member lookup table.
void createObjCMemberLookup();
void createObjCMethodLookup();
public:
ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc,
@@ -3108,12 +3108,20 @@ public:
/// Look in this class and its extensions (but not any of its protocols or
/// superclasses) for declarations with a given Objective-C selector.
///
/// Note that this can find methods, initializers, getters, and setters.
ArrayRef<ValueDecl *> lookupDirect(ObjCSelector selector);
/// Note that this can find methods, initializers, deinitializers,
/// getters, and setters.
///
/// \param selector The Objective-C selector of the method we're
/// looking for.
///
/// \param isInstance Whether we are looking for an instance method
/// (vs. a class method).
MutableArrayRef<AbstractFunctionDecl *> lookupDirect(ObjCSelector selector,
bool isInstance);
/// Record the presence of an @objc member whose Objective-C name has been
/// Record the presence of an @objc method whose Objective-C name has been
/// finalized.
void recordObjCMember(ValueDecl *vd);
void recordObjCMethod(AbstractFunctionDecl *method);
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) {