diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-10-26 17:18:00 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-10-26 17:18:00 +0000 |
commit | 53e4b55d2c534cfd59021ff18349ac58979ce43f (patch) | |
tree | 07535f12c88eee35b89dd74e81e392c72b618b04 /lib/Sema/SemaLookup.cpp | |
parent | 8e6285af719adc6f86d6faa235d22a08eb68ee3a (diff) |
Teach typo correction not to return the same keyword that matches a
typo. This can happen with context-sensitive keywords like "super",
when typo correction didn't know that "super" wasn't permitted in this
context.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117372 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 67d22ee924..e36642cb7c 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3181,10 +3181,14 @@ DeclarationName Sema::CorrectTypo(LookupResult &Res, Scope *S, CXXScopeSpec *SS, // Make sure that the user typed at least 3 characters for each correction // made. Otherwise, we don't even both looking at the results. + + // We also suppress exact matches; those should be handled by a + // different mechanism (e.g., one that introduces qualification in + // C++). unsigned ED = Consumer.getBestEditDistance(); if (ED > 0 && Typo->getName().size() / ED < 3) { // If this was an unqualified lookup, note that no correction was found. - if (IsUnqualifiedLookup) + if (IsUnqualifiedLookup && ED > 0) (void)UnqualifiedTyposCorrected[Typo]; return DeclarationName(); @@ -3244,6 +3248,14 @@ DeclarationName Sema::CorrectTypo(LookupResult &Res, Scope *S, CXXScopeSpec *SS, if (Consumer.begin()->second) { Res.suppressDiagnostics(); Res.clear(); + + // Don't correct to a keyword that's the same as the typo; the keyword + // wasn't actually in scope. + if (ED == 0) { + Res.setLookupName(Typo); + return DeclarationName(); + } + } else if (!LastLookupWasAccepted) { // Perform name lookup on this name. LookupPotentialTypoResult(*this, Res, Name, S, SS, MemberContext, @@ -3264,6 +3276,13 @@ DeclarationName Sema::CorrectTypo(LookupResult &Res, Scope *S, CXXScopeSpec *SS, Res.suppressDiagnostics(); Res.clear(); + // Don't correct to a keyword that's the same as the typo; the keyword + // wasn't actually in scope. + if (ED == 0) { + Res.setLookupName(Typo); + return DeclarationName(); + } + // Record the correction for unqualified lookup. if (IsUnqualifiedLookup) UnqualifiedTyposCorrected[Typo] |