forked from OSchip/llvm-project
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:
parent
674ef1d7d3
commit
0b1d28866c
|
@ -429,6 +429,7 @@ def SelectorTypeMismatch : DiagGroup<"selector-type-mismatch">;
|
||||||
def Selector : DiagGroup<"selector", [SelectorTypeMismatch]>;
|
def Selector : DiagGroup<"selector", [SelectorTypeMismatch]>;
|
||||||
def Protocol : DiagGroup<"protocol">;
|
def Protocol : DiagGroup<"protocol">;
|
||||||
def AtProtocol : DiagGroup<"at-protocol">;
|
def AtProtocol : DiagGroup<"at-protocol">;
|
||||||
|
def PropertyAccessDotSyntax: DiagGroup<"property-access-dot-syntax">;
|
||||||
def PropertyAttr : DiagGroup<"property-attribute-mismatch">;
|
def PropertyAttr : DiagGroup<"property-attribute-mismatch">;
|
||||||
def SuperSubClassMismatch : DiagGroup<"super-class-method-mismatch">;
|
def SuperSubClassMismatch : DiagGroup<"super-class-method-mismatch">;
|
||||||
def OverridingMethodMismatch : DiagGroup<"overriding-method-mismatch">;
|
def OverridingMethodMismatch : DiagGroup<"overriding-method-mismatch">;
|
||||||
|
|
|
@ -6910,6 +6910,9 @@ def err_property_not_found_suggest : Error<
|
||||||
"property %0 not found on object of type %1; did you mean %2?">;
|
"property %0 not found on object of type %1; did you mean %2?">;
|
||||||
def err_ivar_access_using_property_syntax_suggest : Error<
|
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?">;
|
"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<
|
def err_property_found_suggest : Error<
|
||||||
"property %0 found on object of type %1; did you mean to access "
|
"property %0 found on object of type %1; did you mean to access "
|
||||||
"it with the \".\" operator?">;
|
"it with the \".\" operator?">;
|
||||||
|
|
|
@ -1700,6 +1700,18 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
|
||||||
if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
|
if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
|
||||||
return ExprError();
|
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 (Getter || Setter) {
|
||||||
if (Super)
|
if (Super)
|
||||||
return new (Context)
|
return new (Context)
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -124,15 +124,16 @@ int main (void) {
|
||||||
@synthesize t, T;
|
@synthesize t, T;
|
||||||
@synthesize Pxyz, pxyz;
|
@synthesize Pxyz, pxyz;
|
||||||
- (id) Meth {
|
- (id) Meth {
|
||||||
self.P = 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;
|
self.q = 0; // expected-warning {{property 'q' not found on object of type 'rdar11363363 *'; did you mean to access property Q?}}
|
||||||
// rdar://11528439
|
// 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.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.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;
|
self.r = 0;
|
||||||
return self.R; // expected-error {{no getter method for read from property}}
|
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
|
@end
|
||||||
|
|
||||||
|
@ -150,7 +151,7 @@ int main (void) {
|
||||||
|
|
||||||
- (void) dealloc
|
- (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
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue