Skip to content

Commit d5e48d7

Browse files
authored
Merge pull request #58822 from ahoppen/pr/effectful-specifier
[CodeCompletion] Annotate variables with effectful getters
2 parents ff0444b + 66b08c5 commit d5e48d7

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

lib/IDE/CompletionLookup.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,16 @@ void CompletionLookup::addVarDeclRef(const VarDecl *VD,
870870

871871
if (isUnresolvedMemberIdealType(VarType))
872872
Builder.addFlair(CodeCompletionFlairBit::ExpressionSpecific);
873+
874+
if (auto Accessor = VD->getEffectfulGetAccessor()) {
875+
if (auto AFT = getTypeOfMember(Accessor, dynamicLookupInfo)->getAs<AnyFunctionType>()) {
876+
if (Accessor->hasImplicitSelfDecl()) {
877+
AFT = AFT->getResult()->getAs<AnyFunctionType>();
878+
assert(AFT);
879+
}
880+
addEffectsSpecifiers(Builder, AFT, Accessor);
881+
}
882+
}
873883
}
874884

875885
/// Return whether \p param has a non-desirable default value for code
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
var globalAsyncVar: Int {
5+
get async {
6+
42
7+
}
8+
}
9+
10+
var globalAsyncThrowingVar: Int {
11+
get async throws {
12+
42
13+
}
14+
}
15+
16+
struct Foo {
17+
var asyncProperty: Int {
18+
get async {
19+
42
20+
}
21+
}
22+
23+
var asyncThrowingProperty: Int {
24+
get async throws {
25+
42
26+
}
27+
}
28+
29+
func asyncFunc() async -> Int { 42 }
30+
func asyncThrowingFunc() async throws -> Int { 42 }
31+
32+
func testMember(f: Foo) async throws {
33+
f.#^MEMBER^#
34+
}
35+
36+
func testGlobal() async throws {
37+
#^GLOBAL^#
38+
}
39+
}
40+
41+
// MEMBER: Begin completions
42+
// MEMBER-DAG: Decl[InstanceVar]/CurrNominal: asyncProperty[#Int#][' async'];
43+
// MEMBER-DAG: Decl[InstanceVar]/CurrNominal: asyncThrowingProperty[#Int#][' async'][' throws'];
44+
// MEMBER-DAG: Decl[InstanceMethod]/CurrNominal: asyncFunc()[' async'][#Int#];
45+
// MEMBER-DAG: Decl[InstanceMethod]/CurrNominal: asyncThrowingFunc()[' async'][' throws'][#Int#];
46+
// MEMBER: End completions
47+
48+
// GLOBAL: Begin completions
49+
// GLOBAL-DAG: Decl[GlobalVar]/CurrModule: globalAsyncVar[#Int#][' async'];
50+
// GLOBAL-DAG: Decl[GlobalVar]/CurrModule: globalAsyncThrowingVar[#Int#][' async'][' throws']
51+
// GLOBAL: End completions

0 commit comments

Comments
 (0)