Skip to content

Commit 0a7c3b9

Browse files
authored
Merge pull request #29346 from rintaro/ide-completion-rdar58778439
[LookupVisibleDecls] Look through DynamicSelfType in meta type lookup
2 parents 6dec36e + 43ad81c commit 0a7c3b9

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ static void lookupVisibleMemberDeclsImpl(
538538
// The metatype represents an arbitrary named type: dig through to the
539539
// declared type to see what we're dealing with.
540540
Type Ty = MTT->getInstanceType();
541+
if (auto dynSelfTy = Ty->getAs<DynamicSelfType>())
542+
Ty = dynSelfTy->getSelfType();
541543
if (Ty->is<AnyMetatypeType>())
542544
return;
543545

test/IDE/complete_after_sself.swift

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_INIT_MyClass | %FileCheck %s --check-prefixes=CHECK-MyClass
2+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_DEINIT_MyClass | %FileCheck %s --check-prefixes=CHECK-MyClass
3+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_INIT_MyClass | %FileCheck %s --check-prefixes=CHECK-MyClass
4+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_INSTANCEMETHOD_MyClass | %FileCheck %s --check-prefixes=CHECK-MyClass
5+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_STATICMETHOD_MyClass | %FileCheck %s --check-prefixes=CHECK-MyClass
6+
7+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_INIT_MyStruct | %FileCheck %s --check-prefixes=CHECK-MyStruct
8+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_DEINIT_MyStruct | %FileCheck %s --check-prefixes=CHECK-MyStruct
9+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_INIT_MyStruct | %FileCheck %s --check-prefixes=CHECK-MyStruct
10+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_INSTANCEMETHOD_MyStruct | %FileCheck %s --check-prefixes=CHECK-MyStruct
11+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_STATICMETHOD_MyStruct | %FileCheck %s --check-prefixes=CHECK-MyStruct
12+
13+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_INIT_MyProto | %FileCheck %s --check-prefixes=CHECK-MyProto
14+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_DEINIT_MyProto | %FileCheck %s --check-prefixes=CHECK-MyProto
15+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_INIT_MyProto | %FileCheck %s --check-prefixes=CHECK-MyProto
16+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_INSTANCEMETHOD_MyProto | %FileCheck %s --check-prefixes=CHECK-MyProto
17+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SSELF_DOT_IN_STATICMETHOD_MyProto | %FileCheck %s --check-prefixes=CHECK-MyProto
18+
19+
class MyClass {
20+
init() {
21+
Self.#^SSELF_DOT_IN_INIT_MyClass^#
22+
}
23+
deinit {
24+
Self.#^SSELF_DOT_IN_DEINIT_MyClass^#
25+
}
26+
func instanceMethod() {
27+
Self.#^SSELF_DOT_IN_INSTANCEMETHOD_MyClass^#
28+
}
29+
static func staticMethod() {
30+
Self.#^SSELF_DOT_IN_STATICMETHOD_MyClass^#
31+
}
32+
// CHECK-MyClass: Begin completions, 5 items
33+
// CHECK-MyClass-DAG: Keyword[self]/CurrNominal: self[#Self.Type#];
34+
// CHECK-MyClass-DAG: Keyword/CurrNominal: Type[#Self.Type#];
35+
// CHECK-MyClass-DAG: Decl[Constructor]/CurrNominal: init()[#MyClass#];
36+
// CHECK-MyClass-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod({#(self): MyClass#})[#() -> Void#];
37+
// CHECK-MyClass-DAG: Decl[StaticMethod]/CurrNominal: staticMethod()[#Void#];
38+
// CHECK-MyClass: End completions
39+
}
40+
41+
struct MyStruct {
42+
init() {
43+
Self.#^SSELF_DOT_IN_INIT_MyStruct^#
44+
}
45+
deinit {
46+
Self.#^SSELF_DOT_IN_DEINIT_MyStruct^#
47+
}
48+
func instanceMethod() {
49+
Self.#^SSELF_DOT_IN_INSTANCEMETHOD_MyStruct^#
50+
}
51+
static func staticMethod() {
52+
Self.#^SSELF_DOT_IN_STATICMETHOD_MyStruct^#
53+
}
54+
// CHECK-MyStruct: Begin completions, 5 items
55+
// CHECK-MyStruct-DAG: Keyword[self]/CurrNominal: self[#MyStruct.Type#];
56+
// CHECK-MyStruct-DAG: Keyword/CurrNominal: Type[#MyStruct.Type#];
57+
// CHECK-MyStruct-DAG: Decl[Constructor]/CurrNominal: init()[#MyStruct#];
58+
// CHECK-MyStruct-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod({#(self): MyStruct#})[#() -> Void#];
59+
// CHECK-MyStruct-DAG: Decl[StaticMethod]/CurrNominal: staticMethod()[#Void#];
60+
// CHECK-MyStruct: End completions
61+
}
62+
63+
protocol MyProto { }
64+
extension MyProto {
65+
init() {
66+
Self.#^SSELF_DOT_IN_INIT_MyProto^#
67+
}
68+
deinit {
69+
Self.#^SSELF_DOT_IN_DEINIT_MyProto^#
70+
}
71+
func instanceMethod() {
72+
Self.#^SSELF_DOT_IN_INSTANCEMETHOD_MyProto^#
73+
}
74+
static func staticMethod() {
75+
Self.#^SSELF_DOT_IN_STATICMETHOD_MyProto^#
76+
}
77+
// CHECK-MyProto: Begin completions, 5 items
78+
// CHECK-MyProto-DAG: Keyword[self]/CurrNominal: self[#Self.Type#];
79+
// CHECK-MyProto-DAG: Keyword/CurrNominal: Type[#Self.Type#];
80+
// CHECK-MyProto-DAG: Decl[Constructor]/CurrNominal: init()[#MyProto#];
81+
// CHECK-MyProto-DAG: Decl[InstanceMethod]/CurrNominal: instanceMethod({#(self): MyProto#})[#() -> Void#];
82+
// CHECK-MyProto-DAG: Decl[StaticMethod]/CurrNominal: staticMethod()[#Void#];
83+
// CHECK-MyProto: End completions
84+
}

0 commit comments

Comments
 (0)