diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/Sema.h | 4 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 33 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 2a77f21a2d..6cad4b2f14 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -2872,6 +2872,10 @@ public: const IdentifierInfo *Name); void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); + void CompareMethodParamsInBaseAndSuper(Decl *IDecl, + ObjCMethodDecl *MethodDecl, + bool IsInstance); + void MergeProtocolPropertiesIntoClass(Decl *CDecl, DeclPtrTy MergeProtocols); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 26f590578c..0ee0ad730f 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1464,6 +1464,37 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, AddInstanceMethodToGlobalPool(SetterMethod); } +void Sema::CompareMethodParamsInBaseAndSuper(Decl *ClassDecl, + ObjCMethodDecl *Method, + bool IsInstance) { + if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) + while (ObjCInterfaceDecl *SD = ID->getSuperClass()) { + if (ObjCMethodDecl *SuperMethodDecl = + SD->lookupMethod(Method->getSelector(), IsInstance)) { + ObjCMethodDecl::param_iterator ParamI = Method->param_begin(), + E = Method->param_end(); + ObjCMethodDecl::param_iterator PrevI = + SuperMethodDecl->param_begin(); + for (; ParamI != E; ++ParamI, ++PrevI) { + assert(PrevI != SuperMethodDecl->param_end() && "Param mismatch"); + QualType T1 = Context.getCanonicalType((*ParamI)->getType()); + QualType T2 = Context.getCanonicalType((*PrevI)->getType()); + if (T1 != T2) { + AssignConvertType ConvTy = CheckAssignmentConstraints(T1, T2); + if (ConvTy == Incompatible || ConvTy == IncompatiblePointer) { + Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super) + << T1 << T2; + Diag(SuperMethodDecl->getLocation(), + diag::note_previous_declaration); + return; + } + } + } + } + ID = SD; + } +} + // Note: For class/category implemenations, allMethods/allProperties is // always null. void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, @@ -1509,6 +1540,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, InsMap[Method->getSelector()] = Method; /// The following allows us to typecheck messages to "id". AddInstanceMethodToGlobalPool(Method); + CompareMethodParamsInBaseAndSuper(ClassDecl, Method, true); } } else { @@ -1526,6 +1558,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, ClsMap[Method->getSelector()] = Method; /// The following allows us to typecheck messages to "Class". AddFactoryMethodToGlobalPool(Method); + CompareMethodParamsInBaseAndSuper(ClassDecl, Method, false); } } } |