r215250 - Objective-C [qoi]. Issue warning and fixit if property-dot syntax
Fariborz Jahanian
fjahanian at apple.com
Fri Aug 8 15:33:25 PDT 2014
Author: fjahanian
Date: Fri Aug 8 17:33:24 2014
New Revision: 215250
URL: http://llvm.org/viewvc/llvm-project?rev=215250&view=rev
Log:
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
Added:
cfe/trunk/test/FixIt/property-access-fixit.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/property-user-setter.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=215250&r1=215249&r2=215250&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Aug 8 17:33:24 2014
@@ -429,6 +429,7 @@ def SelectorTypeMismatch : DiagGroup<"se
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">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=215250&r1=215249&r2=215250&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug 8 17:33:24 2014
@@ -6910,6 +6910,9 @@ def err_property_not_found_suggest : Err
"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?">;
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=215250&r1=215249&r2=215250&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Aug 8 17:33:24 2014
@@ -1700,6 +1700,18 @@ HandleExprPropertyRefExpr(const ObjCObje
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)
Added: cfe/trunk/test/FixIt/property-access-fixit.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/property-access-fixit.m?rev=215250&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/property-access-fixit.m (added)
+++ cfe/trunk/test/FixIt/property-access-fixit.m Fri Aug 8 17:33:24 2014
@@ -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
+
+ at class BridgeFormatter;
+
+ at interface NSObject
++ (id)new;
+ at end
+
+ at interface X : NSObject
+ at property int x;
+ at property int Y;
+ at property(assign, readwrite, getter=formatter, setter=setFormatter:) BridgeFormatter* cppFormatter;
+ at end
+
+ at implementation X
+- (void) endit
+{
+ self.formatter = 0;
+}
+ at end
+
+int main()
+{
+ X *obj = [X new];
+ obj.X = 3;
+ obj.y = 4;
+ return obj.x + obj.Y;
+}
Modified: cfe/trunk/test/SemaObjC/property-user-setter.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-user-setter.m?rev=215250&r1=215249&r2=215250&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-user-setter.m (original)
+++ cfe/trunk/test/SemaObjC/property-user-setter.m Fri Aug 8 17:33:24 2014
@@ -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
More information about the cfe-commits
mailing list