aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDeclObjC.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-01-04 17:27:12 +0000
committerDouglas Gregor <dgregor@apple.com>2010-01-04 17:27:12 +0000
commit95ff742380d1c3dd5152739183bfe085cf27197f (patch)
tree6535008592d8aac8bb73a8baf33cc639a050717b /lib/Sema/SemaDeclObjC.cpp
parent3f27b384801de26ce7efaa395699b42719372f24 (diff)
When declaring an Objective-C implementation without a corresponding
interface, suggest correction of typos. For example, given: @interface NSString @end @implementation NSstring @end we'll warn with: t.m:4:19: warning: cannot find interface declaration for 'NSstring'; did you mean 'NSString'? @implementation NSstring ^ However, since this is just a warning, we don't provide a fix-it hint. Good idea, Ted! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92488 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclObjC.cpp')
-rw-r--r--lib/Sema/SemaDeclObjC.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 6ff898970a..fb2cc712dc 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -689,13 +689,27 @@ Sema::DeclPtrTy Sema::ActOnStartClassImplementation(
if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
- } else {
- // Is there an interface declaration of this class; if not, warn!
- IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
- if (!IDecl || IDecl->isForwardDecl()) {
+ } else if ((IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl))) {
+ // If this is a forward declaration of an interface, warn.
+ if (IDecl->isForwardDecl()) {
Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
IDecl = 0;
}
+ } else {
+ // We did not find anything with the name ClassName; try to correct for
+ // typos in the class name.
+ LookupResult R(*this, ClassName, ClassLoc, LookupOrdinaryName);
+ if (CorrectTypo(R, TUScope, 0) &&
+ (IDecl = R.getAsSingle<ObjCInterfaceDecl>())) {
+ // Suggest the (potentially) correct interface name. However, don't
+ // provide a code-modification hint or use the typo name for recovery,
+ // because this is just a warning. The program may actually be correct.
+ Diag(ClassLoc, diag::warn_undef_interface_suggest)
+ << ClassName << R.getLookupName();
+ IDecl = 0;
+ } else {
+ Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
+ }
}
// Check that super class name is valid class name