From: Fariborz Jahanian Date: Wed, 9 Mar 2011 22:17:12 +0000 (+0000) Subject: Property setter/getter must be looked up in property type's X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27569b0f3e1b27f609a2e104b39bad077850e210;p=clang Property setter/getter must be looked up in property type's list of protocols as well. // rdar://9078584 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127367 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 5826f296c1..6b6600740f 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -465,6 +465,10 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, Selector Sel = PP.getSelectorTable().getNullarySelector(Member); ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Sel); + + // May be founf in property's qualified list. + if (!Getter) + Getter = LookupMethodInQualifiedType(Sel, OPT, true); // If this reference is in an @implementation, check for 'private' methods. if (!Getter) @@ -484,6 +488,11 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, SelectorTable::constructSetterName(PP.getIdentifierTable(), PP.getSelectorTable(), Member); ObjCMethodDecl *Setter = IFace->lookupInstanceMethod(SetterSel); + + // May be founf in property's qualified list. + if (!Setter) + Setter = LookupMethodInQualifiedType(SetterSel, OPT, true); + if (!Setter) { // If this reference is in an @implementation, also check for 'private' // methods. @@ -492,7 +501,7 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, // Look through local category implementations associated with the class. if (!Setter) Setter = IFace->getCategoryInstanceMethod(SetterSel); - + if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc)) return ExprError(); @@ -1087,15 +1096,9 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver, if (const ObjCObjectPointerType *QIdTy = ReceiverType->getAsObjCQualifiedIdType()) { // Search protocols for instance methods. - for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(), - E = QIdTy->qual_end(); I != E; ++I) { - ObjCProtocolDecl *PDecl = *I; - if (PDecl && (Method = PDecl->lookupInstanceMethod(Sel))) - break; - // Since we aren't supporting "Class", look for a class method. - if (PDecl && (Method = PDecl->lookupClassMethod(Sel))) - break; - } + Method = LookupMethodInQualifiedType(Sel, QIdTy, true); + if (!Method) + Method = LookupMethodInQualifiedType(Sel, QIdTy, false); } else if (const ObjCObjectPointerType *OCIType = ReceiverType->getAsObjCInterfacePointerType()) { // We allow sending a message to a pointer to an interface (an object). @@ -1105,14 +1108,10 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver, // The idea is to add class info to MethodPool. Method = ClassDecl->lookupInstanceMethod(Sel); - if (!Method) { + if (!Method) // Search protocol qualifiers. - for (ObjCObjectPointerType::qual_iterator QI = OCIType->qual_begin(), - E = OCIType->qual_end(); QI != E; ++QI) { - if ((Method = (*QI)->lookupInstanceMethod(Sel))) - break; - } - } + Method = LookupMethodInQualifiedType(Sel, OCIType, true); + bool forwardClass = false; if (!Method) { // If we have implementations in scope, check "private" methods. diff --git a/test/SemaObjC/objc-qualified-property-lookup.m b/test/SemaObjC/objc-qualified-property-lookup.m new file mode 100644 index 0000000000..daf583de33 --- /dev/null +++ b/test/SemaObjC/objc-qualified-property-lookup.m @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9078584 + +@interface NSObject @end + +@protocol TextInput +-editRange; +@end + +@interface I { + NSObject* editor; +} +- (id) Meth; +@end + +@implementation I +- (id) Meth { + return editor.editRange; +} +@end +