From: Fariborz Jahanian Date: Sat, 15 Feb 2014 00:04:36 +0000 (+0000) Subject: [Objective-C Sema]. Warn when an indirectly overridden property X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ca6b0185a36eba0614ac98a9f3bbfcca725a997;p=clang [Objective-C Sema]. Warn when an indirectly overridden property mismatches the one declared in current class; in addition to those that are directly overridden. // rdar://15967517 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201446 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index c8358bccb6..992ac1de90 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -204,7 +204,8 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, if (ObjCInterfaceDecl *IFace = dyn_cast(ClassDecl)) { // For a class, compare the property against a property in our superclass. bool FoundInSuper = false; - if (ObjCInterfaceDecl *Super = IFace->getSuperClass()) { + ObjCInterfaceDecl *CurrentInterfaceDecl = IFace; + while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) { DeclContext::lookup_result R = Super->lookup(Res->getDeclName()); for (unsigned I = 0, N = R.size(); I != N; ++I) { if (ObjCPropertyDecl *SuperProp = dyn_cast(R[I])) { @@ -213,12 +214,17 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, break; } } + if (FoundInSuper) + break; + else + CurrentInterfaceDecl = Super; } if (FoundInSuper) { // Also compare the property against a property in our protocols. - for (ObjCInterfaceDecl::protocol_iterator P = IFace->protocol_begin(), - PEnd = IFace->protocol_end(); + for (ObjCInterfaceDecl::protocol_iterator + P = CurrentInterfaceDecl->protocol_begin(), + PEnd = CurrentInterfaceDecl->protocol_end(); P != PEnd; ++P) { CheckPropertyAgainstProtocol(*this, Res, *P, KnownProtos); } diff --git a/test/SemaObjC/property-inherited.m b/test/SemaObjC/property-inherited.m index f5f1b420c2..cd223ddd1f 100644 --- a/test/SemaObjC/property-inherited.m +++ b/test/SemaObjC/property-inherited.m @@ -44,3 +44,29 @@ @property(assign) Data *p_base; @property(assign) NSData *p_data; // expected-warning{{property type 'NSData *' is incompatible with type 'NSMutableData *' inherited from 'Base'}} @end + +// rdar://15967517 +@protocol P1 +@property (nonatomic) void* selected; +@end + +@protocol P2 +@property (nonatomic) void* selected; // expected-note {{property declared here}} +@end + +@interface MKAnnotationView +@property (nonatomic) void* selected; // expected-note {{property declared here}} +@property (nonatomic) char selected2; +@end + +@interface Parent : MKAnnotationView +@property (nonatomic) void* selected1; // expected-note {{property declared here}} +@property (nonatomic) char selected2; +@end + +@interface Child : Parent +@property (nonatomic) char selected; // expected-warning {{property type 'char' is incompatible with type 'void *' inherited from 'MKAnnotationView'}} \ + // expected-warning {{property type 'char' is incompatible with type 'void *' inherited from 'P2'}} +@property (nonatomic) char selected1; // expected-warning {{property type 'char' is incompatible with type 'void *' inherited from 'Parent'}} +@property (nonatomic) char selected2; +@end