Objective-C [qoi]. Issue warning and fixit if property-dot syntax

use mis-cased property name (which is currently accepted silently
due to the way property setters are named). rdar://17911746

llvm-svn: 215250
This commit is contained in:
Fariborz Jahanian 2014-08-08 22:33:24 +00:00
parent 674ef1d7d3
commit 0b1d28866c
5 changed files with 53 additions and 5 deletions

View File

@ -429,6 +429,7 @@ def SelectorTypeMismatch : DiagGroup<"selector-type-mismatch">;
def Selector : DiagGroup<"selector", [SelectorTypeMismatch]>;
def Protocol : DiagGroup<"protocol">;
def AtProtocol : DiagGroup<"at-protocol">;
def PropertyAccessDotSyntax: DiagGroup<"property-access-dot-syntax">;
def PropertyAttr : DiagGroup<"property-attribute-mismatch">;
def SuperSubClassMismatch : DiagGroup<"super-class-method-mismatch">;
def OverridingMethodMismatch : DiagGroup<"overriding-method-mismatch">;

View File

@ -6910,6 +6910,9 @@ def err_property_not_found_suggest : Error<
"property %0 not found on object of type %1; did you mean %2?">;
def err_ivar_access_using_property_syntax_suggest : Error<
"property %0 not found on object of type %1; did you mean to access instance variable %2?">;
def warn_property_access_suggest : Warning<
"property %0 not found on object of type %1; did you mean to access property %2?">,
InGroup<PropertyAccessDotSyntax>;
def err_property_found_suggest : Error<
"property %0 found on object of type %1; did you mean to access "
"it with the \".\" operator?">;

View File

@ -1700,6 +1700,18 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
return ExprError();
// Special warning if member name used in a property-dot for a setter accessor
// does not use a property with same name; e.g. obj.X = ... for a property with
// name 'x'.
if (Setter && Setter->isImplicit() && Setter->isPropertyAccessor()
&& !IFace->FindPropertyDeclaration(Member)) {
if (const ObjCPropertyDecl *PDecl = Setter->findPropertyDecl())
Diag(MemberLoc,
diag::warn_property_access_suggest)
<< MemberName << QualType(OPT, 0) << PDecl->getName()
<< FixItHint::CreateReplacement(MemberLoc, PDecl->getName());
}
if (Getter || Setter) {
if (Super)
return new (Context)

View File

@ -0,0 +1,31 @@
// RUN: cp %s %t
// RUN: %clang_cc1 -x objective-c -fixit %t
// RUN: %clang_cc1 -x objective-c -Werror %t
//rdar://17911746
@class BridgeFormatter;
@interface NSObject
+ (id)new;
@end
@interface X : NSObject
@property int x;
@property int Y;
@property(assign, readwrite, getter=formatter, setter=setFormatter:) BridgeFormatter* cppFormatter;
@end
@implementation X
- (void) endit
{
self.formatter = 0;
}
@end
int main()
{
X *obj = [X new];
obj.X = 3;
obj.y = 4;
return obj.x + obj.Y;
}

View File

@ -124,15 +124,16 @@ int main (void) {
@synthesize t, T;
@synthesize Pxyz, pxyz;
- (id) Meth {
self.P = 0;
self.q = 0;
self.P = 0; // expected-warning {{property 'P' not found on object of type 'rdar11363363 *'; did you mean to access property p?}}
self.q = 0; // expected-warning {{property 'q' not found on object of type 'rdar11363363 *'; did you mean to access property Q?}}
// rdar://11528439
self.t = 0; // expected-error {{synthesized properties 't' and 'T' both claim setter 'setT:'}}
self.T = 0; // expected-error {{synthesized properties 'T' and 't' both claim setter 'setT:'}}
self.Pxyz = 0; // expected-error {{synthesized properties 'Pxyz' and 'pxyz' both claim setter 'setPxyz:'}}
self.pxyz = 0; // expected-error {{synthesized properties 'pxyz' and 'Pxyz' both claim setter 'setPxyz:'}}
self.R = 0;
return self.R; // expected-error {{no getter method for read from property}}
self.r = 0;
return self.R; // expected-error {{no getter method for read from property}} \
// expected-warning {{property 'R' not found on object of type 'rdar11363363 *'; did you mean to access property r?}}
}
@end
@ -150,7 +151,7 @@ int main (void) {
- (void) dealloc
{
self.formatter = 0;
self.formatter = 0; // expected-warning {{property 'formatter' not found on object of type 'FMXBridgeFormatter *'; did you mean to access property cppFormatter?}}
}
@end