From c220a18ecdfa42ebb3ce267974cf24e343e2aa6d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 19 Apr 2010 18:02:19 +0000 Subject: [PATCH] When searching for code-completion and typo-correction candidates, look from an Objective-C class or category to its implementation, to pick up synthesized ivars. Fixes a problem reported by David Chisnall. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101792 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaLookup.cpp | 15 +++++++++++++++ test/FixIt/typo.m | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 29b25a5dc3..abc0ed381e 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -2279,6 +2279,14 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result, LookupVisibleDecls(IFace->getSuperClass(), Result, QualifiedNameLookup, true, Consumer, Visited); } + + // If there is an implementation, traverse it. We do this to find + // synthesized ivars. + if (IFace->getImplementation()) { + ShadowContextRAII Shadow(Visited); + LookupVisibleDecls(IFace->getImplementation(), Result, + QualifiedNameLookup, true, Consumer, Visited); + } } else if (ObjCProtocolDecl *Protocol = dyn_cast(Ctx)) { for (ObjCProtocolDecl::protocol_iterator I = Protocol->protocol_begin(), E = Protocol->protocol_end(); I != E; ++I) { @@ -2293,6 +2301,13 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result, LookupVisibleDecls(*I, Result, QualifiedNameLookup, false, Consumer, Visited); } + + // If there is an implementation, traverse it. + if (Category->getImplementation()) { + ShadowContextRAII Shadow(Visited); + LookupVisibleDecls(Category->getImplementation(), Result, + QualifiedNameLookup, true, Consumer, Visited); + } } } diff --git a/test/FixIt/typo.m b/test/FixIt/typo.m index fa0918a1e6..00eb642a18 100644 --- a/test/FixIt/typo.m +++ b/test/FixIt/typo.m @@ -103,3 +103,37 @@ void test2(Collide *a) { } @end + +@interface Ivar +@end + +@protocol Proto +@property (retain) id ivar; +@end + +@interface User +- (void)method; +@end + +@implementation User +@synthesize ivar; + +- (void)method { + [ivar method]; // Test that we don't correct 'ivar' to 'Ivar' +} +@end + +@interface User2 +@end + +@interface User2 (Cat) < Proto> +- (void)method; +@end + +@implementation User2 (Cat) +@synthesize ivar; + +- (void)method { + [ivar method]; // Test that we don't correct 'ivar' to 'Ivar' +} +@end -- 2.40.0