Skip to content

Commit 7cabbe0

Browse files
author
Fariborz Jahanian
committed
Improve diagnostics when property being looked up
in a forward @Class object. // rdar://8774513 llvm-svn: 121933
1 parent 9613a09 commit 7cabbe0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,10 @@ def err_ref_array_type : Error<
24162416
"cannot refer to declaration with an array type inside block">;
24172417
def err_property_not_found : Error<
24182418
"property %0 not found on object of type %1">;
2419+
def err_property_not_found_forward_class : Error<
2420+
"property %0 cannot be found in forward class object %1">;
2421+
def note_forward_class : Note<
2422+
"forward class is declared here">;
24192423
def err_duplicate_property : Error<
24202424
"property has a previous declaration">;
24212425
def ext_gnu_void_ptr : Extension<

clang/lib/Sema/SemaExprObjC.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
353353
ObjCInterfaceDecl *IFace = IFaceT->getDecl();
354354
IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
355355

356+
if (IFace->isForwardDecl()) {
357+
Diag(MemberLoc, diag::err_property_not_found_forward_class)
358+
<< MemberName << QualType(OPT, 0);
359+
Diag(IFace->getLocation(), diag::note_forward_class);
360+
return ExprError();
361+
}
356362
// Search for a declared property first.
357363
if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(Member)) {
358364
// Check whether we can reference this property.

clang/test/SemaObjC/property-9.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,14 @@ @interface MyStyleIntf
9696
- (float)setMyStyle:(int)style;
9797
@end
9898

99+
// rdar://8774513
100+
@class MDAInstance; // expected-note {{forward class is declared here}}
101+
102+
@interface MDATestDocument
103+
@property(retain) MDAInstance *instance;
104+
@end
105+
106+
id f0(MDATestDocument *d) {
107+
return d.instance.path; // expected-error {{property 'path' cannot be found in forward class object 'MDAInstance *'}}
108+
}
109+

0 commit comments

Comments
 (0)