Skip to content

Commit f65005c

Browse files
authored
Merge pull request swiftlang#29092 from rintaro/ide-completion-guardstmt-rdar28482216
[CodeCompletion] Suggest local variables in a multi-clause guard statement condition
2 parents 6a7f840 + 90f7f34 commit f65005c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,8 @@ void FindLocalVal::visitGuardStmt(GuardStmt *S) {
25072507
return;
25082508

25092509
// Names in the guard aren't visible until after the body.
2510-
if (!isReferencePointInRange(S->getBody()->getSourceRange()))
2510+
if (S->getBody()->isImplicit() ||
2511+
!isReferencePointInRange(S->getBody()->getSourceRange()))
25112512
checkStmtCondition(S->getCond());
25122513

25132514
visit(S->getBody());

test/IDE/complete_stmt_controlling_expr.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GUARD_LET_BIND_4 | %FileCheck %s -check-prefix=FOOSTRUCT_DOT_BOOL
118118
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GUARD_LET_BIND_5 | %FileCheck %s -check-prefix=FOOSTRUCT_DOT
119119
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GUARD_LET_BIND_6 | %FileCheck %s -check-prefix=FOOSTRUCT_NODOT
120-
120+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GUARD_LET_BIND_7 | %FileCheck %s -check-prefix=FOOSTRUCT_LOCALVAL
121+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GUARD_LET_BIND_8 | %FileCheck %s -check-prefix=FOOSTRUCT_LOCALVAL
121122

122123
struct FooStruct {
123124
var instanceVar : Int
@@ -605,6 +606,13 @@ func testGuardLetBinding5(x: FooStruct?) {
605606
func testGuardLetBinding5(x: FooStruct?) {
606607
guard let y = x, z = y#^GUARD_LET_BIND_6^# else {}
607608
}
609+
func testGuardLetBinding7(x: FooStruct?) {
610+
guard let boundVal = x, let other = #^GUARD_LET_BIND_7^# else {}
611+
}
612+
func testGuardLetBinding8(_ x: FooStruct?) {
613+
guard let boundVal = x, let other = testGuardLetBinding8(#^GUARD_LET_BIND_8^#) else {}
614+
}
615+
608616

609617
// FOOSTRUCT_DOT: Begin completions
610618
// FOOSTRUCT_DOT-DAG: Decl[InstanceVar]/CurrNominal: instanceVar[#Int#];
@@ -623,3 +631,7 @@ func testGuardLetBinding5(x: FooStruct?) {
623631
// FOOSTRUCT_NODOT-DAG: Decl[InstanceMethod]/CurrNominal: .boolGen()[#Bool#];
624632
// FOOSTRUCT_NODOT-DAG: Decl[InstanceMethod]/CurrNominal: .intGen()[#Int#];
625633
// FOOSTRUCT_NODOT: End completions
634+
635+
// FOOSTRUCT_LOCALVAL: Begin completions
636+
// FOOSTRUCT_LOCALVAL-DAG: Decl[LocalVar]/Local{{(/TypeRelation\[Convertible\])?}}: boundVal[#FooStruct#];
637+
// FOOSTRUCT_LOCALVAL: End completions

0 commit comments

Comments
 (0)