aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-03-23 19:02:22 +0000
committerTed Kremenek <kremenek@apple.com>2010-03-23 19:02:22 +0000
commitf921a4868cf1876636f6684e7f68697b18c0cb47 (patch)
tree812cacbc1c0f9aaf87017017ef637a79a1145cd5
parent5fb12c6c8f64d4b69f65faefb7d0800d7e4bca66 (diff)
Improve diagnostic for @property/ivar type mismatch by including the types of the
ivar and @property respectively. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99312 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--lib/Sema/SemaObjCProperty.cpp8
-rw-r--r--test/SemaObjC/property-ivar-mismatch.m4
-rw-r--r--test/SemaObjC/property.m4
4 files changed, 12 insertions, 7 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index ddd87941e2..f774e6860b 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -348,7 +348,7 @@ def error_synthesized_ivar_yet_not_supported : Error<
" (need to declare %0 explicitly)">;
def error_property_ivar_type : Error<
- "type of property %0 does not match type of ivar %1">;
+ "type of property %0 (%1) does not match type of ivar %2 (%3)">;
def error_ivar_in_superclass_use : Error<
"property %0 attempting to use ivar %1 declared in super class %2">;
def error_weak_property : Error<
@@ -530,6 +530,7 @@ def err_implicit_object_parameter_init : Error<
"of type %1">;
def note_field_decl : Note<"member is declared here">;
+def note_ivar_decl : Note<"ivar is declared here">;
def note_bitfield_decl : Note<"bit-field is declared here">;
def note_previous_decl : Note<"%0 declared here">;
def note_member_synthesized_at : Note<
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp
index 030fdaafbc..4dc734de8a 100644
--- a/lib/Sema/SemaObjCProperty.cpp
+++ b/lib/Sema/SemaObjCProperty.cpp
@@ -383,7 +383,9 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
if (PropType != IvarType) {
if (CheckAssignmentConstraints(PropType, IvarType) != Compatible) {
Diag(PropertyLoc, diag::error_property_ivar_type)
- << property->getDeclName() << Ivar->getDeclName();
+ << property->getDeclName() << PropType
+ << Ivar->getDeclName() << IvarType;
+ Diag(Ivar->getLocation(), diag::note_ivar_decl);
// Note! I deliberately want it to fall thru so, we have a
// a property implementation and to avoid future warnings.
}
@@ -396,7 +398,9 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
if (lhsType != rhsType &&
lhsType->isArithmeticType()) {
Diag(PropertyLoc, diag::error_property_ivar_type)
- << property->getDeclName() << Ivar->getDeclName();
+ << property->getDeclName() << PropType
+ << Ivar->getDeclName() << IvarType;
+ Diag(Ivar->getLocation(), diag::note_ivar_decl);
// Fall thru - see previous comment
}
// __weak is explicit. So it works on Canonical type.
diff --git a/test/SemaObjC/property-ivar-mismatch.m b/test/SemaObjC/property-ivar-mismatch.m
index ea3acfc3fc..16ff338550 100644
--- a/test/SemaObjC/property-ivar-mismatch.m
+++ b/test/SemaObjC/property-ivar-mismatch.m
@@ -3,12 +3,12 @@
@interface Test4
{
- char ivar;
+ char ivar; // expected-note{{ivar is declared here}}
}
@property int prop;
@end
@implementation Test4
-@synthesize prop = ivar; // expected-error {{type of property 'prop' does not match type of ivar 'ivar'}}
+@synthesize prop = ivar; // expected-error {{type of property 'prop' ('int') does not match type of ivar 'ivar' ('char')}}
@end
diff --git a/test/SemaObjC/property.m b/test/SemaObjC/property.m
index b7f0fcaa76..4d00bd2b52 100644
--- a/test/SemaObjC/property.m
+++ b/test/SemaObjC/property.m
@@ -2,7 +2,7 @@
@interface I
{
- int IVAR;
+ int IVAR; // expected-note{{ivar is declared here}}
int name;
}
@property int d1;
@@ -19,7 +19,7 @@
@synthesize d1; // expected-error {{synthesized property 'd1' must either be named the same as}}
@dynamic bad; // expected-error {{property implementation must have its declaration in interface 'I'}}
@synthesize prop_id; // expected-error {{synthesized property 'prop_id' must either be named the same}} // expected-note {{previous declaration is here}}
-@synthesize prop_id = IVAR; // expected-error {{type of property 'prop_id' does not match type of ivar 'IVAR'}} // expected-error {{property 'prop_id' is already implemented}}
+@synthesize prop_id = IVAR; // expected-error {{type of property 'prop_id' ('id') does not match type of ivar 'IVAR' ('int')}} // expected-error {{property 'prop_id' is already implemented}}
@synthesize name; // OK! property with same name as an accessible ivar of same name
@end