From 5921b83f54135612c36c54e61edabbe26a55ffb7 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 23 Mar 2010 19:02:22 +0000 Subject: [PATCH] Improve diagnostic for @property/ivar type mismatch by including the types of the ivar and @property respectively. llvm-svn: 99312 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 ++- clang/lib/Sema/SemaObjCProperty.cpp | 8 ++++++-- clang/test/SemaObjC/property-ivar-mismatch.m | 4 ++-- clang/test/SemaObjC/property.m | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index ddd87941e24c..f774e6860bfa 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/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/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp index 030fdaafbc0d..4dc734de8ae9 100644 --- a/clang/lib/Sema/SemaObjCProperty.cpp +++ b/clang/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/clang/test/SemaObjC/property-ivar-mismatch.m b/clang/test/SemaObjC/property-ivar-mismatch.m index ea3acfc3fcf9..16ff33855061 100644 --- a/clang/test/SemaObjC/property-ivar-mismatch.m +++ b/clang/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/clang/test/SemaObjC/property.m b/clang/test/SemaObjC/property.m index b7f0fcaa7629..4d00bd2b522d 100644 --- a/clang/test/SemaObjC/property.m +++ b/clang/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