Author: David Goldman Date: 2020-06-08T12:46:00-04:00 New Revision: 2ef65adb6f9dbebdd250dc6210e813711fb478d9
URL: https://github.com/llvm/llvm-project/commit/2ef65adb6f9dbebdd250dc6210e813711fb478d9 DIFF: https://github.com/llvm/llvm-project/commit/2ef65adb6f9dbebdd250dc6210e813711fb478d9.diff LOG: [Sema][CodeComplete][ObjC] Don't include arrow/dot fixits Summary: Exempt ObjC from arrow/dot fixits since this has limited value for Objective-C, where properties (referenced by dot syntax) are normally backed by ivars (referenced by arrow syntax). In addition, the current implementation doesn't properly mark the fix it condition for Objective-C. This was initially added in https://reviews.llvm.org/D41537 for C++ and then later C, don't believe the Objective-C changes were intentional. Reviewers: sammccall, yvvan Subscribers: jfb, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D81263 Added: clang/test/CodeCompletion/objc-member-access.m Modified: clang/lib/Sema/SemaCodeComplete.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 0aad0568714f..5539aef917d0 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -5195,7 +5195,12 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Results.AddResult(std::move(Result)); } } else if (!IsArrow && BaseType->isObjCObjectPointerType()) { - // Objective-C property reference. + // Objective-C property reference. Bail if we're performing fix-it code + // completion since Objective-C properties are normally backed by ivars, + // most Objective-C fix-its here would have little value. + if (AccessOpFixIt.hasValue()) { + return false; + } AddedPropertiesSet AddedProperties; if (const ObjCObjectPointerType *ObjCPtr = @@ -5215,7 +5220,12 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, /*InOriginalClass*/ false); } else if ((IsArrow && BaseType->isObjCObjectPointerType()) || (!IsArrow && BaseType->isObjCObjectType())) { - // Objective-C instance variable access. + // Objective-C instance variable access. Bail if we're performing fix-it + // code completion since Objective-C properties are normally backed by + // ivars, most Objective-C fix-its here would have little value. + if (AccessOpFixIt.hasValue()) { + return false; + } ObjCInterfaceDecl *Class = nullptr; if (const ObjCObjectPointerType *ObjCPtr = BaseType->getAs<ObjCObjectPointerType>()) diff --git a/clang/test/CodeCompletion/objc-member-access.m b/clang/test/CodeCompletion/objc-member-access.m new file mode 100644 index 000000000000..b3dbd85af91b --- /dev/null +++ b/clang/test/CodeCompletion/objc-member-access.m @@ -0,0 +1,22 @@ +// Note: the run lines follow their respective tests, since line/column +// matter in this test. + +@interface TypeWithPropertiesBackedByIvars { + int _bar; + int _foo; +} +@property(nonatomic) int foo; +@property(nonatomic) int bar; +@end + +int getFoo(id object) { + TypeWithPropertiesBackedByIvars *model = (TypeWithPropertiesBackedByIvars *)object; + int foo = model.; + return foo; +} + +// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:14:19 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s +// CHECK-CC1-NOT: [#int#]_bar +// CHECK-CC1-NOT: [#int#]_foo +// CHECK-CC1: [#int#]bar +// CHECK-CC1: [#int#]foo _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits