Skip to content

Commit 1167701

Browse files
committed
[CodeCompletion] Handle @autoclosure in context type analysis
If the context is '@autoclosure' parameter, the context type should be the result type of it. rdar://problem/65802490 (cherry picked from commit 3e558f0)
1 parent 5ad3d0e commit 1167701

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
@@ -790,6 +790,8 @@ class ExprContextAnalyzer {
790790
auto argTy = ty;
791791
if (paramType.isInOut())
792792
argTy = InOutType::get(argTy);
793+
else if (paramType.isAutoClosure() && argTy->is<AnyFunctionType>())
794+
argTy = argTy->castTo<AnyFunctionType>()->getResult();
793795
if (seenTypes.insert(argTy.getPointer()).second)
794796
recordPossibleType(argTy);
795797
}

test/IDE/complete_unresolved_members.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TERNARY_5 | %FileCheck %s -check-prefix=UNRESOLVED_3_NOTIDEAL
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
125+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AUTOCLOSURE | %FileCheck %s -check-prefix=UNRESOLVED_3
126+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AUTOCLOSURE_OPT | %FileCheck %s -check-prefix=UNRESOLVED_3_OPT
127+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AUTOCLOSURE_FUNCTY | %FileCheck %s -check-prefix=UNRESOLVED_3
128+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=AUTOCLOSURE_FUNCTY_OPT | %FileCheck %s -check-prefix=UNRESOLVED_3_OPT
125129

126130
enum SomeEnum1 {
127131
case South
@@ -783,3 +787,19 @@ func testTernaryOperator2(cond: Bool) {
783787
// TERNARY_CONDITION-DAG: Decl[Constructor]/CurrNominal/IsSystem/TypeRelation[Identical]: init()[#Bool#]; name=init()
784788
// TERNARY_CONDITION: End completions
785789
}
790+
791+
func receiveAutoclosure(_: @autoclosure () -> SomeEnum1) {}
792+
func receiveAutoclosureOpt(_: @autoclosure () -> SomeEnum1?) {}
793+
func testAutoclosre() {
794+
receiveAutoclosure(.#^AUTOCLOSURE^#)
795+
// Same as UNRESOLVED_3
796+
797+
receiveAutoclosureOpt(.#^AUTOCLOSURE_OPT^#)
798+
// Same as UNRESOLVED_3_OPT
799+
}
800+
func testAutoclosreFuncTy(fn: (@autoclosure () -> SomeEnum1) -> Void, fnOpt: (@autoclosure () -> SomeEnum1?) -> Void) {
801+
fn(.#^AUTOCLOSURE_FUNCTY^#)
802+
// Same as UNRESOLVED_3
803+
fnOpt(.#^AUTOCLOSURE_FUNCTY_OPT^#)
804+
// Same as UNRESOLVED_3_OPT
805+
}

0 commit comments

Comments
 (0)