Skip to content

Commit ca9c68d

Browse files
authored
Merge pull request swiftlang#16831 from AnthonyLatsis/invalid-metatype-completions
[CodeCompletion] Remove static member completions from metatypes
2 parents 27dcffd + 873700f commit ca9c68d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/AST/LookupVisibleDecls.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ static void lookupVisibleMemberDeclsImpl(
503503
// The metatype represents an arbitrary named type: dig through to the
504504
// declared type to see what we're dealing with.
505505
Type Ty = MTT->getInstanceType();
506+
if (Ty->is<AnyMetatypeType>())
507+
return;
506508

507509
LookupState subLS = LookupState::makeQualified().withOnMetatype();
508510
if (LS.isIncludingInstanceMembers()) {

test/IDE/complete_value_expr.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_OBJECT_NO_DOT_2 | %FileCheck %s -check-prefix=FOO_OBJECT_NO_DOT
88
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_STRUCT_DOT_1 | %FileCheck %s -check-prefix=FOO_STRUCT_DOT
99
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_STRUCT_NO_DOT_1 | %FileCheck %s -check-prefix=FOO_STRUCT_NO_DOT
10+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_STRUCT_META_1 | %FileCheck %s -check-prefix=FOO_STRUCT_META
11+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_STRUCT_META_2 | %FileCheck %s -check-prefix=FOO_STRUCT_META
1012

1113
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICITLY_CURRIED_FUNC_0 | %FileCheck %s -check-prefix=IMPLICITLY_CURRIED_FUNC_0
1214
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICITLY_CURRIED_FUNC_1 | %FileCheck %s -check-prefix=IMPLICITLY_CURRIED_FUNC_1
@@ -501,6 +503,21 @@ func testMetatypeExprWithoutDot() {
501503
FooStruct#^FOO_STRUCT_NO_DOT_1^#
502504
}
503505

506+
struct NoMetaCompletions {
507+
static var foo: Int = 0
508+
class func bar() {}
509+
typealias Foo = Int
510+
}
511+
func testMetatypeCompletions() {
512+
NoMetaCompletions.Type.#^FOO_STRUCT_META_1^#
513+
}
514+
func testMetatypeCompletionsWithoutDot() {
515+
NoMetaCompletions.Type#^FOO_STRUCT_META_2^#
516+
}
517+
// FOO_STRUCT_META-NOT: Decl
518+
// FOO_STRUCT_META: Keyword[self]/CurrNominal: {{self|.self}}[#NoMetaCompletions.Type.Type#]; name=self
519+
// FOO_STRUCT_META-NOT: Decl
520+
504521
func testImplicitlyCurriedFunc(_ fs: inout FooStruct) {
505522
FooStruct.instanceFunc0(&fs)#^IMPLICITLY_CURRIED_FUNC_0^#
506523
// IMPLICITLY_CURRIED_FUNC_0: Begin completions

0 commit comments

Comments
 (0)