From a4b984d8396724a8e1137c22186c558c0cb0bf3f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Sat, 24 Sep 2011 00:56:59 +0000 Subject: [PATCH] objc - redeclaration of property in extension class must match property type declaration in its primary class. // rdar://10142679 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140438 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ lib/Sema/SemaObjCProperty.cpp | 8 +++++++- test/SemaObjC/continuation-class-property.m | 19 +++++++++++++++++++ test/SemaObjCXX/property-synthesis-error.mm | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 0dd84d221d..5da5288cca 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -516,6 +516,9 @@ def warn_default_atomic_custom_getter_setter : Warning< def err_use_continuation_class : Error< "illegal redeclaration of property in continuation class %0" " (attribute must be 'readwrite', while its primary must be 'readonly')">; +def error_type_mismatch_continuation_class : Error< + "type of property %0 in continuation class does not match" + "property type in primary class">; 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 " diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 2bb54560b7..6284f36e41 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -235,7 +235,13 @@ Sema::HandlePropertyInClassExtension(Scope *S, /* lexicalDC = */ CDecl); return PDecl; } - + if (PIDecl->getType().getCanonicalType() + != PDecl->getType().getCanonicalType()) { + Diag(AtLoc, + diag::error_type_mismatch_continuation_class) << PDecl->getType(); + Diag(PIDecl->getLocation(), diag::note_property_declare); + } + // The property 'PIDecl's readonly attribute will be over-ridden // with continuation class's readwrite property attribute! unsigned PIkind = PIDecl->getPropertyAttributesAsWritten(); diff --git a/test/SemaObjC/continuation-class-property.m b/test/SemaObjC/continuation-class-property.m index c48a23d62a..e398ae5498 100644 --- a/test/SemaObjC/continuation-class-property.m +++ b/test/SemaObjC/continuation-class-property.m @@ -22,3 +22,22 @@ @property (readwrite, copy) id foos; @end + +// rdar://10142679 +@class NSString; + +typedef struct { + float width; + float length; +} NSRect; + +@interface MyClass { +} +@property (readonly) NSRect foo; // expected-note {{property declared here}} +@property (readonly, strong) NSString *bar; // expected-note {{property declared here}} +@end + +@interface MyClass () +@property (readwrite) NSString *foo; // expected-error {{type of property 'NSString *' in continuation class does not matchproperty type in primary class}} +@property (readwrite, strong) NSRect bar; // expected-error {{type of property 'NSRect' in continuation class does not matchproperty type in primary class}} +@end diff --git a/test/SemaObjCXX/property-synthesis-error.mm b/test/SemaObjCXX/property-synthesis-error.mm index c7a279cfd7..c67f0a45c7 100644 --- a/test/SemaObjCXX/property-synthesis-error.mm +++ b/test/SemaObjCXX/property-synthesis-error.mm @@ -10,7 +10,7 @@ NSMutableArray * _array; } -@property (readonly) NSArray * array; +@property (readonly) NSMutableArray * array; @end -- 2.40.0