Improve error reporting of property and setter/getter
type mimatches.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60630 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index 933993b..ac204b1 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -571,6 +571,8 @@
"property attribute in continuation class does not match the primary class")
DIAG(err_accessor_property_type_mismatch, ERROR,
"type of property %0 does not match type of accessor %1")
+DIAG(note_declared_at, NOTE,
+ "declared at")
DIAG(err_setter_type_void, ERROR,
"type of setter must be void")
DIAG(warn_conflicting_types, WARNING,
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 83013a7..a5ffb70 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -933,21 +933,25 @@
const ObjCMethodDecl *GetterMethod,
const ObjCMethodDecl *SetterMethod) {
if (GetterMethod &&
- GetterMethod->getResultType() != property->getType())
+ GetterMethod->getResultType() != property->getType()) {
Diag(property->getLocation(),
diag::err_accessor_property_type_mismatch)
<< property->getDeclName()
<< GetterMethod->getSelector().getAsIdentifierInfo();
+ Diag(GetterMethod->getLocation(), diag::note_declared_at);
+ }
if (SetterMethod) {
if (SetterMethod->getResultType() != Context.VoidTy)
Diag(SetterMethod->getLocation(), diag::err_setter_type_void);
if (SetterMethod->getNumParams() != 1 ||
- (SetterMethod->getParamDecl(0)->getType() != property->getType()))
+ (SetterMethod->getParamDecl(0)->getType() != property->getType())) {
Diag(property->getLocation(),
diag::err_accessor_property_type_mismatch)
<< property->getDeclName()
<< SetterMethod->getSelector().getAsIdentifierInfo();
+ Diag(SetterMethod->getLocation(), diag::note_declared_at);
+ }
}
}
diff --git a/test/SemaObjC/property-typecheck-1.m b/test/SemaObjC/property-typecheck-1.m
index c02cbe0..d5ee8d1 100644
--- a/test/SemaObjC/property-typecheck-1.m
+++ b/test/SemaObjC/property-typecheck-1.m
@@ -1,7 +1,7 @@
// RUN: clang -fsyntax-only -verify %s
@interface A
--(float) x;
+-(float) x; // expected-note {{declared at}}
@property int x; // expected-error {{type of property 'x' does not match type of accessor 'x'}}
@end