Tweak diagnostics for redeclaration of a @property in a class extension where the redelcaration and original

declaration have the 'readwrite' attribute.  This is a common case, and we can issue a more lucid diagnostic.

Fixes <rdar://problem/7629420>.

llvm-svn: 117045
This commit is contained in:
Ted Kremenek 2010-10-21 18:49:42 +00:00
parent 22813f4077
commit 5ef9ad9907
4 changed files with 24 additions and 9 deletions

View File

@ -365,8 +365,12 @@ def warn_atomic_property_rule : Warning<
"writable atomic property %0 cannot pair a synthesized setter/getter "
"with a user defined setter/getter">;
def err_use_continuation_class : Error<
"illegal declaration of property in continuation class %0"
": attribute must be readwrite, while its primary must be readonly">;
"illegal redeclaration of property in continuation class %0"
" (attribute must be 'readwrite', while its primary must be 'readonly')">;
def err_use_continuation_class_redeclaration_readwrite : Error<
"illegal redeclaration of 'readwrite' property in continuation class %0"
" (perhaps you intended this to be a 'readwrite' redeclaration of a "
"'readonly' public property?)">;
def err_continuation_class : Error<"continuation class has no primary class">;
def err_property_type : Error<"property cannot have array or function type %0">;
def error_missing_property_context : Error<

View File

@ -187,7 +187,16 @@ Sema::HandlePropertyInClassExtension(Scope *S, ObjCCategoryDecl *CDecl,
PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
PIDecl->setSetterName(SetterSel);
} else {
Diag(AtLoc, diag::err_use_continuation_class)
// Tailor the diagnostics for the common case where a readwrite
// property is declared both in the @interface and the continuation.
// This is a common error where the user often intended the original
// declaration to be readonly.
unsigned diag =
(Attributes & ObjCDeclSpec::DQ_PR_readwrite) &&
(PIkind & ObjCPropertyDecl::OBJC_PR_readwrite)
? diag::err_use_continuation_class_redeclaration_readwrite
: diag::err_use_continuation_class;
Diag(AtLoc, diag)
<< CCPrimary->getDeclName();
Diag(PIDecl->getLocation(), diag::note_property_declare);
}

View File

@ -12,7 +12,7 @@
@interface ReadOnly ()
@property(readwrite, copy) id object; // expected-warning {{property attribute in continuation class does not match the primary class}}
@property(readonly) id object1; // expected-error {{illegal declaration of property in continuation class 'ReadOnly': attribute must be}}
@property(readonly) id object1; // expected-error {{illegal redeclaration of property in continuation class 'ReadOnly' (attribute must be 'readwrite', while its primary must be 'readonly')}}
@property (readwrite, assign) int indentLevel; // OK. assign the the default in any case.
@end
@ -31,8 +31,8 @@
@end
@interface Bar ()
@property (copy) id foo; // expected-error {{illegal declaration of property in continuation class 'Bar': attribute must be}}
@property (copy) id fee; // expected-error {{illegal declaration of property in continuation class 'Bar': attribute must be}}
@property (copy) id foo; // expected-error {{illegal redeclaration of property in continuation class 'Bar' (attribute must be 'readwrite', while its primary must be 'readonly')}}
@property (copy) id fee; // expected-error {{illegal redeclaration of property in continuation class 'Bar' (attribute must be 'readwrite', while its primary must be 'readonly')}}
@end
@implementation Bar

View File

@ -2,20 +2,22 @@
@interface Foo
@property (readonly) char foo; // expected-note {{property declared here}}
@property (readwrite) char bar; // expected-note {{property declared here}}
@end
@interface Foo ()
@property (readwrite) char foo; // OK
@property (readwrite) char NewProperty; // expected-note 2 {{property declared here}}
@property (readwrite) char bar; // expected-error{{illegal redeclaration of 'readwrite' property in continuation class 'Foo' (perhaps you intended this to be a 'readwrite' redeclaration of a 'readonly' public property?)}}
@end
@interface Foo ()
@property (readwrite) char foo; // OK again, make primary property readwrite for 2nd time!
@property (readwrite) char NewProperty; // expected-error {{illegal declaration of property in continuation class 'Foo': attribute must be readwrite, while its primary must be readonly}}
@property (readwrite) char NewProperty; // expected-error {{redeclaration of property in continuation class 'Foo' (attribute must be 'readwrite', while its primary must be 'readonly')}}
@end
@interface Foo ()
@property (readonly) char foo; // expected-error {{illegal declaration of property in continuation class 'Foo': attribute must be readwrite, while its primary must be readonly}}
@property (readwrite) char NewProperty; // expected-error {{illegal declaration of property in continuation class 'Foo': attribute must be readwrite, while its primary must be readonly}}
@property (readonly) char foo; // expected-error {{redeclaration of property in continuation class 'Foo' (attribute must be 'readwrite', while its primary must be 'readonly')}}
@property (readwrite) char NewProperty; // expected-error {{redeclaration of property in continuation class 'Foo' (attribute must be 'readwrite', while its primary must be 'readonly')}}
@end