Skip to content

Commit c6cd4b0

Browse files
authored
Merge pull request #33217 from rintaro/ide-completion-rdar65802490
[CodeCompletion] Handle @autoclosure in context type analysis
2 parents 22409d7 + 3e558f0 commit c6cd4b0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ class ExprContextAnalyzer {
819819
auto argTy = ty;
820820
if (paramType.isInOut())
821821
argTy = InOutType::get(argTy);
822+
else if (paramType.isAutoClosure() && argTy->is<AnyFunctionType>())
823+
argTy = argTy->castTo<AnyFunctionType>()->getResult();
822824
if (seenTypes.insert(argTy.getPointer()).second)
823825
recordPossibleType(argTy);
824826
}

test/IDE/complete_unresolved_members.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@
123123
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TERNARY_6 | %FileCheck %s -check-prefix=UNRESOLVED_3_NOTIDEAL
124124
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TERNARY_CONDITION | %FileCheck %s -check-prefix=TERNARY_CONDITION
125125
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOADED_CLOSURE_RETURN | %FileCheck %s -check-prefix=OVERLOADED_CLOSURE_RETURN
126+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AUTOCLOSURE | %FileCheck %s -check-prefix=UNRESOLVED_3
127+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AUTOCLOSURE_OPT | %FileCheck %s -check-prefix=UNRESOLVED_3_OPT
128+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AUTOCLOSURE_FUNCTY | %FileCheck %s -check-prefix=UNRESOLVED_3
129+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AUTOCLOSURE_FUNCTY_OPT | %FileCheck %s -check-prefix=UNRESOLVED_3_OPT
126130

127131
enum SomeEnum1 {
128132
case South
@@ -798,3 +802,19 @@ func testClosureReturnTypeForOverloaded() {
798802
// OVERLOADED_CLOSURE_RETURN-DAG: Decl[EnumElement]/CurrNominal/TypeRelation[Identical]: West[#SomeEnum2#];
799803
// OVERLOADED_CLOSURE_RETURN: End completions
800804
}
805+
806+
func receiveAutoclosure(_: @autoclosure () -> SomeEnum1) {}
807+
func receiveAutoclosureOpt(_: @autoclosure () -> SomeEnum1?) {}
808+
func testAutoclosre() {
809+
receiveAutoclosure(.#^AUTOCLOSURE^#)
810+
// Same as UNRESOLVED_3
811+
812+
receiveAutoclosureOpt(.#^AUTOCLOSURE_OPT^#)
813+
// Same as UNRESOLVED_3_OPT
814+
}
815+
func testAutoclosreFuncTy(fn: (@autoclosure () -> SomeEnum1) -> Void, fnOpt: (@autoclosure () -> SomeEnum1?) -> Void) {
816+
fn(.#^AUTOCLOSURE_FUNCTY^#)
817+
// Same as UNRESOLVED_3
818+
fnOpt(.#^AUTOCLOSURE_FUNCTY_OPT^#)
819+
// Same as UNRESOLVED_3_OPT
820+
}

0 commit comments

Comments
 (0)