[cfe-commits] r117372 - in /cfe/trunk: lib/Sema/SemaLookup.cpp test/FixIt/typo.m

Douglas Gregor dgregor at apple.com
Tue Oct 26 10:18:00 PDT 2010


Author: dgregor
Date: Tue Oct 26 12:18:00 2010
New Revision: 117372

URL: http://llvm.org/viewvc/llvm-project?rev=117372&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/FixIt/typo.m

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=117372&r1=117371&r2=117372&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Oct 26 12:18:00 2010
@@ -3181,10 +3181,14 @@
 
   // 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 @@
     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 @@
     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]

Modified: cfe/trunk/test/FixIt/typo.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.m?rev=117372&r1=117371&r2=117372&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/typo.m (original)
+++ cfe/trunk/test/FixIt/typo.m Tue Oct 26 12:18:00 2010
@@ -102,6 +102,7 @@
 @interface Super
 - (int)method; // expected-note{{using}}
 - (int)method2;
+- (int)method3:(id)x;
 @end
 
 @interface Sub : Super
@@ -155,3 +156,11 @@
   [A methodA] // expected-error{{expected ';' after expression}}
 }
 
+#ifdef NON_FIXITS
+ at implementation Sub3
+- (int)method2 {
+  int x = super; // expected-note{{use of undeclared identifier 'super'; did you mean 'Super'?}}
+  return 0;
+}
+ at end
+#endif





More information about the cfe-commits mailing list