diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-05-18 16:14:23 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-05-18 16:14:23 +0000 |
commit | 91f7ac7e20ba03b8cd711974e2611231077bbe81 (patch) | |
tree | 2757ecaab670e65e51bdd4081dfa40642a347316 | |
parent | d425d2b78665f42dddda56da31d6a3f576493474 (diff) |
Tweak typo-correction logic a bit regarding "super", so that we
consider "super" as a candidate whenever we're parsing an expression
within an Objective-C method in an interface that has a superclass. At
some point, we'd like to give "super" a little edge over non-local
names; that will come later.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104022 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/Sema.h | 3 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 2 | ||||
-rw-r--r-- | test/FixIt/typo.m | 17 |
5 files changed, 28 insertions, 6 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index a7d242c559..975516ff9a 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1811,7 +1811,8 @@ public: bool HasTrailingLParen, bool IsAddressOfOperand); - bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R); + bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, + CorrectTypoContext CTC = CTC_Unknown); OwningExprResult LookupInObjCMethod(LookupResult &R, Scope *S, diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 5af5585f7f..8bc3d063b1 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -917,7 +917,7 @@ static void DiagnoseInstanceReference(Sema &SemaRef, /// /// \return false if new lookup candidates were found bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, - LookupResult &R) { + LookupResult &R, CorrectTypoContext CTC) { DeclarationName Name = R.getLookupName(); unsigned diagnostic = diag::err_undeclared_var_use; @@ -968,7 +968,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, // We didn't find anything, so try to correct for a typo. DeclarationName Corrected; - if (S && (Corrected = CorrectTypo(R, S, &SS))) { + if (S && (Corrected = CorrectTypo(R, S, &SS, false, CTC))) { if (!R.empty()) { if (isa<ValueDecl>(*R.begin()) || isa<FunctionTemplateDecl>(*R.begin())) { if (SS.isEmpty()) @@ -1122,7 +1122,7 @@ Sema::OwningExprResult Sema::ActOnIdExpression(Scope *S, // If this name wasn't predeclared and if this is not a function // call, diagnose the problem. if (R.empty()) { - if (DiagnoseEmptyLookup(S, SS, R)) + if (DiagnoseEmptyLookup(S, SS, R, CTC_Unknown)) return ExprError(); assert(!R.empty() && diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 31c33e963c..62b0ea149b 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -2612,6 +2612,12 @@ DeclarationName Sema::CorrectTypo(LookupResult &Res, Scope *S, CXXScopeSpec *SS, WantExpressionKeywords = true; WantCXXNamedCasts = true; WantRemainingKeywords = true; + + if (ObjCMethodDecl *Method = getCurMethodDecl()) + if (Method->getClassInterface() && + Method->getClassInterface()->getSuperClass()) + Consumer.addKeywordResult(Context, "super"); + break; case CTC_NoKeywords: diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 15f19723f8..4c48e6159c 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -6002,7 +6002,7 @@ BuildRecoveryCallExpr(Sema &SemaRef, Scope *S, Expr *Fn, LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(), Sema::LookupOrdinaryName); - if (SemaRef.DiagnoseEmptyLookup(S, SS, R)) + if (SemaRef.DiagnoseEmptyLookup(S, SS, R, Sema::CTC_Expression)) return Destroy(SemaRef, Fn, Args, NumArgs); assert(!R.empty() && "lookup results empty despite recovery"); diff --git a/test/FixIt/typo.m b/test/FixIt/typo.m index 2ee6831da6..3b73a2a33b 100644 --- a/test/FixIt/typo.m +++ b/test/FixIt/typo.m @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -DNON_FIXITS -verify %s // RUN: %clang -E -P %s -o %t -// RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fixit %t || true +// RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fixit %t || true // RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -pedantic -Werror %t @interface NSString // expected-note{{'NSString' declared here}} @@ -97,6 +97,7 @@ void test2(Collide *a) { @interface Super - (int)method; // expected-note{{using}} +- (int)method2; @end @interface Sub : Super @@ -110,6 +111,20 @@ void test2(Collide *a) { @end +#ifdef NON_FIXITS +double *isupper(int); + +@interface Sub2 : Super +- (int)method2; +@end + +@implementation Sub2 +- (int)method2 { + return [supper method2]; // expected-error{{use of undeclared identifier 'supper'}} +} +@end +#endif + @interface Ivar @end |