Skip to content

Commit 54a11df

Browse files
authored
Merge pull request #58883 from rintaro/ide-completion-anyobjectinit-rdar93059166
[CodeCompletion] Don't suggest initializers on 'AnyObject'
2 parents a9527d4 + d32b9c8 commit 54a11df

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/IDE/CompletionLookup.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,11 @@ void CompletionLookup::addConstructorCallsForType(
15551555
if (!Sink.addInitsToTopLevel)
15561556
return;
15571557

1558+
// 'AnyObject' is not initializable.
1559+
// FIXME: Should we do this in 'AnyObjectLookupRequest'?
1560+
if (type->isAnyObject())
1561+
return;
1562+
15581563
assert(CurrDeclContext);
15591564

15601565
auto results =

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ static void collectPossibleCalleesByQualifiedLookup(
365365
if (!baseInstanceTy->mayHaveMembers())
366366
return;
367367

368+
// 'AnyObject' is not initializable.
369+
if (baseInstanceTy->isAnyObject() && name == DeclNameRef::createConstructor())
370+
return;
371+
368372
// Make sure we've resolved implicit members.
369373
namelookup::installSemanticMembersIfNeeded(baseInstanceTy, name);
370374

test/IDE/complete_dynamic_lookup.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
// RUN: %FileCheck %s -check-prefix=DL_CLASS_DOT < %t.dl.txt
5757
// RUN: %FileCheck %s -check-prefix=GLOBAL_NEGATIVE < %t.dl.txt
5858

59+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -I %t -disable-objc-attr-requires-foundation-module -code-completion-token=INITIALIZE_PAREN | %FileCheck %s -check-prefix=INITIALIZE_PAREN
60+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -I %t -disable-objc-attr-requires-foundation-module -code-completion-token=GLOBAL_WITHINIT -code-complete-inits-in-postfix-expr | %FileCheck %s -check-prefix=GLOBAL_WITHINIT
61+
5962
// REQUIRES: objc_interop
6063

6164
import foo_swift_module
@@ -491,3 +494,16 @@ func testAnyObjectClassMethods1(_ dl: AnyObject) {
491494
func testAnyObjectClassMethods2(_ dl: AnyObject) {
492495
type(of: dl).#^DL_CLASS_DOT_1^#
493496
}
497+
498+
func testAnyObjectInitialize() {
499+
AnyObject(#^INITIALIZE_PAREN^#)
500+
// INITIALIZE_PAREN-NOT: Flair[ArgLabels]
501+
// INITIALIZE_PAREN-NOT: name=int:
502+
}
503+
504+
func testGlobalInitializer() {
505+
#^GLOBAL_WITHINIT^#
506+
// GLOBAL_WITHINIT-NOT: name=AnyObject(
507+
// GLOBAL_WITHINIT-DAG: Decl[TypeAlias]/OtherModule[Swift]/IsSystem: AnyObject[#Builtin.AnyObject#]; name=AnyObject
508+
// GLOBAL_WITHINIT-NOT: name=AnyObject(
509+
}

0 commit comments

Comments
 (0)