Improve diagnostics when property names an object type of

a forward class. // rdar://8851803

llvm-svn: 125699
This commit is contained in:
Fariborz Jahanian 2011-02-17 01:26:14 +00:00
parent 669a25aec3
commit 05d389f407
3 changed files with 30 additions and 0 deletions

View File

@ -2567,6 +2567,8 @@ def err_getter_not_found : Error<
"expected getter method not found on object of type %0">;
def err_property_not_found_forward_class : Error<
"property %0 cannot be found in forward class object %1">;
def err_property_not_as_forward_class : Error<
"property %0 names an object of forward class type in class object %1">;
def note_forward_class : Note<
"forward class is declared here">;
def err_duplicate_property : Error<

View File

@ -520,6 +520,22 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
return HandleExprPropertyRefExpr(OPT, BaseExpr, TypoResult, MemberLoc,
SuperLoc, SuperType, Super);
}
ObjCInterfaceDecl *ClassDeclared;
if (ObjCIvarDecl *Ivar =
IFace->lookupInstanceVariable(Member, ClassDeclared)) {
QualType T = Ivar->getType();
if (const ObjCObjectPointerType * OBJPT =
T->getAsObjCInterfacePointerType()) {
const ObjCInterfaceType *IFaceT = OBJPT->getInterfaceType();
if (ObjCInterfaceDecl *IFace = IFaceT->getDecl())
if (IFace->isForwardDecl()) {
Diag(MemberLoc, diag::err_property_not_as_forward_class)
<< MemberName << QualType(OPT, 0);
Diag(IFace->getLocation(), diag::note_forward_class);
return ExprError();
}
}
}
Diag(MemberLoc, diag::err_property_not_found)
<< MemberName << QualType(OPT, 0);

View File

@ -20,3 +20,15 @@ void f3(id o)
o.foo; // expected-error{{property 'foo' not found on object of type 'id'}}
}
// rdar://8851803
@class SomeOtherClass; // expected-note {{forward class is declared here}}
@interface MyClass {
SomeOtherClass *someOtherObject;
}
@end
void foo(MyClass *myObject) {
myObject.someOtherObject.someProperty = 0; // expected-error {{property 'someOtherObject' names an object of forward class type in class object 'MyClass *'}}
}