diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-01-01 00:15:04 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-01-01 00:15:04 +0000 |
commit | d203a162966cfc2157857f5fdfb0e30a4f669281 (patch) | |
tree | 156f14133ea3275f09dcf01ac209f6be873d07d0 /lib | |
parent | c171e3b192a372669cf622ff0b6a847f8e5b4220 (diff) |
When typo correction for an id-expression finds a type (or Objective-C
class), provide a suggestion for the type or class found. However,
since we can't recover properly in this case, don't provide a fix-it
hint. Example:
test/FixIt/typo.m:8:3: error: use of undeclared identifier 'NSstring';
did you
mean 'NSString'?
NSstring *str = @"A string";
...
^
1 diagnostic generated.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92379 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 6bb6ea3e51..7bf04d88cd 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -931,21 +931,41 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, const CXXScopeSpec &SS, } // We didn't find anything, so try to correct for a typo. - if (S && CorrectTypo(R, S, &SS) && - (isa<ValueDecl>(*R.begin()) || isa<FunctionTemplateDecl>(*R.begin()))) { - if (SS.isEmpty()) - Diag(R.getNameLoc(), diagnostic_suggest) << Name << R.getLookupName() - << CodeModificationHint::CreateReplacement(R.getNameLoc(), + if (S && CorrectTypo(R, S, &SS)) { + if (isa<ValueDecl>(*R.begin()) || isa<FunctionTemplateDecl>(*R.begin())) { + if (SS.isEmpty()) + Diag(R.getNameLoc(), diagnostic_suggest) << Name << R.getLookupName() + << CodeModificationHint::CreateReplacement(R.getNameLoc(), R.getLookupName().getAsString()); - else - Diag(R.getNameLoc(), diag::err_no_member_suggest) - << Name << computeDeclContext(SS, false) << R.getLookupName() - << SS.getRange() - << CodeModificationHint::CreateReplacement(R.getNameLoc(), + else + Diag(R.getNameLoc(), diag::err_no_member_suggest) + << Name << computeDeclContext(SS, false) << R.getLookupName() + << SS.getRange() + << CodeModificationHint::CreateReplacement(R.getNameLoc(), R.getLookupName().getAsString()); - // Tell the callee to try to recover. - return false; + // Tell the callee to try to recover. + return false; + } + + if (isa<TypeDecl>(*R.begin()) || isa<ObjCInterfaceDecl>(*R.begin())) { + // FIXME: If we ended up with a typo for a type name or + // Objective-C class name, we're in trouble because the parser + // is in the wrong place to recover. Suggest the typo + // correction, but don't make it a fix-it since we're not going + // to recover well anyway. + if (SS.isEmpty()) + Diag(R.getNameLoc(), diagnostic_suggest) << Name << R.getLookupName(); + else + Diag(R.getNameLoc(), diag::err_no_member_suggest) + << Name << computeDeclContext(SS, false) << R.getLookupName() + << SS.getRange(); + + // Don't try to recover; it won't work. + return true; + } + + R.clear(); } // Emit a special diagnostic for failed member lookups. |