aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-18 16:30:22 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-18 16:30:22 +0000
commitd0785ea6c4c37a7fa4fcd4840e6e036ffb44e13e (patch)
tree004dd76a732692ae55578018d2b26d2854aae81e
parent91f7ac7e20ba03b8cd711974e2611231077bbe81 (diff)
Give a slight edge to the context-sensitive keyword 'super' over
non-function-local declarations with names similar to what the user typed. For example, this allows us to correct 'supper' to 'super' in an Objective-C message send, even though the C function 'isupper' has the same edit distance. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104023 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaLookup.cpp21
-rw-r--r--test/FixIt/typo.m6
2 files changed, 22 insertions, 5 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 62b0ea149b..774a82b7c7 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -2684,7 +2684,7 @@ DeclarationName Sema::CorrectTypo(LookupResult &Res, Scope *S, CXXScopeSpec *SS,
Consumer.addKeywordResult(Context, "typeof");
}
- if (WantCXXNamedCasts) {
+ if (WantCXXNamedCasts && getLangOptions().CPlusPlus) {
Consumer.addKeywordResult(Context, "const_cast");
Consumer.addKeywordResult(Context, "dynamic_cast");
Consumer.addKeywordResult(Context, "reinterpret_cast");
@@ -2814,6 +2814,25 @@ DeclarationName Sema::CorrectTypo(LookupResult &Res, Scope *S, CXXScopeSpec *SS,
BestIvarOrPropertyDecl = 0;
FoundIvarOrPropertyDecl = false;
Consumer.clear_decls();
+ } else if (CTC == CTC_ObjCMessageReceiver &&
+ (*Consumer.keyword_begin())->isStr("super")) {
+ // In an Objective-C message send, give the "super" keyword a slight
+ // edge over entities not in function or method scope.
+ for (TypoCorrectionConsumer::iterator I = Consumer.begin(),
+ IEnd = Consumer.end();
+ I != IEnd; ++I) {
+ if ((*I)->getDeclName() == BestName) {
+ if ((*I)->getDeclContext()->isFunctionOrMethod())
+ return DeclarationName();
+ }
+ }
+
+ // Everything found was outside a function or method; the 'super'
+ // keyword takes precedence.
+ BestIvarOrPropertyDecl = 0;
+ FoundIvarOrPropertyDecl = false;
+ Consumer.clear_decls();
+ BestName = *Consumer.keyword_begin();
} else {
// Name collision; we will not correct typos.
return DeclarationName();
diff --git a/test/FixIt/typo.m b/test/FixIt/typo.m
index 3b73a2a33b..11447620de 100644
--- a/test/FixIt/typo.m
+++ b/test/FixIt/typo.m
@@ -111,7 +111,6 @@ void test2(Collide *a) {
@end
-#ifdef NON_FIXITS
double *isupper(int);
@interface Sub2 : Super
@@ -120,10 +119,9 @@ double *isupper(int);
@implementation Sub2
- (int)method2 {
- return [supper method2]; // expected-error{{use of undeclared identifier 'supper'}}
+ return [supper method2]; // expected-error{{unknown receiver 'supper'; did you mean 'super'?}}
}
@end
-#endif
@interface Ivar
@end
@@ -138,7 +136,7 @@ double *isupper(int);
@end
@implementation User
-@synthesize ivar;
+@synthesize ivar; // expected-error{{synthesized property 'ivar' must either be named the same as a compatible ivar or must explicitly name an ivar}}
- (void)method {
// Test that we don't correct 'ivar' to 'Ivar' e