Skip to content

Commit fc0e748

Browse files
authored
Merge pull request swiftlang#37324 from rintaro/ide-completion-rdar75358153
[CodeCompletion] Reset 'hasSingleExpressionBody' when setting function body
2 parents 6d782c4 + 72f16df commit fc0e748

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7075,8 +7075,10 @@ BraceStmt *Parser::parseAbstractFunctionBodyImpl(AbstractFunctionDecl *AFD) {
70757075
return nullptr;
70767076

70777077
BraceStmt *BS = Body.get();
7078+
// Reset the single expression body status.
7079+
AFD->setHasSingleExpressionBody(false);
70787080
AFD->setBodyParsed(BS);
7079-
7081+
70807082
if (Parser::shouldReturnSingleExpressionElement(BS->getElements())) {
70817083
auto Element = BS->getLastElement();
70827084
if (auto *stmt = Element.dyn_cast<Stmt *>()) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// BEGIN t1.swift
2+
enum E {
3+
case foo, bar
4+
}
5+
func foo(_ arg: E) {}
6+
func test(val: E) {
7+
foo(.bar)
8+
}
9+
10+
// BEGIN t2.swift
11+
enum E {
12+
case foo, bar
13+
}
14+
func foo(_ arg: E) {}
15+
func test(val: E) {
16+
foo(.bar)
17+
if v
18+
}
19+
20+
// BEGIN dummy.swift
21+
22+
// rdar://75358153
23+
// Previously, completing inside single expression body, then completing inside
24+
// *non* single expression body in the same function caused a crash because the
25+
// "has single expression" flag didn't cleard. This file tests the scenario not
26+
// to regress again.
27+
28+
// RUN: %empty-directory(%t)
29+
// RUN: %{python} %utils/split_file.py -o %t %s
30+
31+
// RUN: %sourcekitd-test \
32+
// RUN: -req=complete -pos=6:8 -text-input %t/t1.swift %t/t.swift -- %t/t.swift == \
33+
// RUN: -req=complete -pos=7:6 -text-input %t/t2.swift %t/t.swift -- %t/t.swift \
34+
// RUN: | %FileCheck %s
35+
36+
// CHECK-LABEL: key.results: [
37+
// CHECK-DAG: key.description: "bar",
38+
// CHECK-DAG: key.description: "foo",
39+
// CHECK-DAG: key.description: "hash(self: E)",
40+
// CHECK: ]
41+
// CHECK-NOT: key.reusingastcontext: 1
42+
43+
// CHECK-LABEL: key.results: [
44+
// CHECK-DAG: key.description: "val",
45+
// CHECK-DAG: key.description: "foo(arg: E)",
46+
// CHECK: ],
47+
// CHECK: key.reusingastcontext: 1

0 commit comments

Comments
 (0)