]> granicus.if.org Git - clang/commitdiff
Fix non-determinism in selecting between equal-length names which refer
authorChandler Carruth <chandlerc@gmail.com>
Tue, 28 Jun 2011 22:48:40 +0000 (22:48 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 28 Jun 2011 22:48:40 +0000 (22:48 +0000)
to the same declaration when correcting typos. This is done by
essentially sorting the corrections as they're added.

Original patch by Kaelyn Uhrain, but modified for style and correctness
by accounting for more than just the textual spelling.

This still is a bit of a WIP hack to make this deterministic. Kaelyn
(and myself) are working on a more principled solution going forward.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134038 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaLookup.cpp

index 6fa7cd673ceabf360146a7047c1d0ce5dd06d8a4..a2e5c7c98f4916e0de68b7035503b90195dbf72a 100644 (file)
@@ -3178,7 +3178,15 @@ void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) {
   TypoResultsMap *& Map = BestResults[Correction.getEditDistance()];
   if (!Map)
     Map = new TypoResultsMap;
-  (*Map)[Name] = Correction;
+
+  TypoCorrection &CurrentCorrection = (*Map)[Name];
+  if (!CurrentCorrection ||
+      // FIXME: The following should be rolled up into an operator< on
+      // TypoCorrection with a more principled definition.
+      CurrentCorrection.isKeyword() < Correction.isKeyword() ||
+      Correction.getAsString(SemaRef.getLangOptions()) <
+      CurrentCorrection.getAsString(SemaRef.getLangOptions()))
+    CurrentCorrection = Correction;
 
   while (BestResults.size() > MaxTypoDistanceResultSets) {
     TypoEditDistanceMap::iterator Last = BestResults.end();