Fix a case where delayed typo correction should have resolved an
authorKaelyn Takata <rikka@google.com>
Fri, 16 Jan 2015 22:11:04 +0000 (22:11 +0000)
committerKaelyn Takata <rikka@google.com>
Fri, 16 Jan 2015 22:11:04 +0000 (22:11 +0000)
commitae9e97c9d6aeeacc07b48a15b49852d1681a2fc1
tree27dfef9643c4906b16ae55441f3d2508c38335d2
parent76723d733bdac9e9f68a0a0b4388d470bfd5e3a0
Fix a case where delayed typo correction should have resolved an
ambiguity but wasn't.

In the new test case, "click" wasn't being corrected properly because
Sema::ClassifyName would call CorrectTypo for "click" then later
Sema::DiagnoseEmptyLookup would call CorrectTypoDelayed for the same use
of "click" (the former by the parser needing to determine what the
identifier is so it knows how to parse the statement, i.e. is it the
beginning of a declaration or an expression). CorrectTypo would record
that typo correction for "click" failed and CorrectTypoDelayed would see
that and not even try to correct the typo, even though in this case
CorrectTypo failed due to an ambiguity (both "Click" and "clock" having
an edit distance of one from "click") that could be resolved with more
information. The fix is two-fold:
  1) Have CorrectTypo not record failed corrections if the reason for
     the failure was two or more corrections with the same edit
     distance, and
  2) Make the CorrectionCandidateCallback used by
     Parser::ParseCastExpression reject FunctionDecl candidates when the
     next token after the identifier is a ".", "=", or "->" since
     functions cannot be assigned to and do not have members that can be
     referenced.

The reason for two correction spots is that from r222549 until r224375
landed, the first correction attempt would fail completely but the
second would suggest "clock" while having the note point to the
declaration of "Click".

llvm-svn: 226334
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaLookup.cpp
clang/test/SemaCXX/typo-correction-delayed.cpp