Skip to content

Commit 95cc452

Browse files
committed
[CodeCompletion] Fix completion in repeat statements
Improve the error recovery so that we get back either a RepeatWhileStmt, or at least a BraceStmt, which code-completion can use to dig out the local variables. rdar://problem/25912182
1 parent 6fa9c8e commit 95cc452

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,8 +1949,6 @@ ParserResult<Stmt> Parser::parseStmtRepeat(LabeledStmtInfo labelInfo) {
19491949
ParserResult<BraceStmt> body =
19501950
parseBraceItemList(diag::expected_lbrace_after_repeat);
19511951
status |= body;
1952-
if (status.hasCodeCompletion())
1953-
return makeParserResult<Stmt>(status, nullptr);
19541952
if (body.isNull())
19551953
body = makeParserResult(
19561954
body, BraceStmt::create(Context, repeatLoc, {}, PreviousLoc, true));
@@ -1972,7 +1970,7 @@ ParserResult<Stmt> Parser::parseStmtRepeat(LabeledStmtInfo labelInfo) {
19721970
condition = parseExpr(diag::expected_expr_repeat_while);
19731971
status |= condition;
19741972
if (condition.isNull()) {
1975-
return makeParserResult<Stmt>(status, nullptr); // FIXME: better recovery
1973+
condition = makeParserErrorResult(new (Context) ErrorExpr(whileLoc));
19761974
}
19771975
}
19781976

test/IDE/complete_repeat.swift

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %swift-ide-test -code-completion -code-completion-token=REPEAT_1 -source-filename=%s | FileCheck %s -check-prefix=REPEAT_1
2+
// RUN: %swift-ide-test -code-completion -code-completion-token=REPEAT_2 -source-filename=%s | FileCheck %s -check-prefix=REPEAT_2
3+
// RUN: %swift-ide-test -code-completion -code-completion-token=REPEAT_3 -source-filename=%s | FileCheck %s -check-prefix=REPEAT_3
4+
// RUN: %swift-ide-test -code-completion -code-completion-token=REPEAT_4 -source-filename=%s | FileCheck %s -check-prefix=REPEAT_4
5+
// RUN: %swift-ide-test -code-completion -code-completion-token=REPEAT_5 -source-filename=%s | FileCheck %s -check-prefix=REPEAT_5
6+
// RUN: %swift-ide-test -code-completion -code-completion-token=REPEAT_COND_1 -source-filename=%s | FileCheck %s -check-prefix=REPEAT_COND_1
7+
8+
repeat {
9+
let local1 = 1
10+
#^REPEAT_1^#
11+
} while true
12+
// REPEAT_1-NOT: LocalVar
13+
// REPEAT_1: Decl[LocalVar]/Local: local1[#Int#];
14+
// REPEAT_1-NOT: LocalVar
15+
16+
repeat {
17+
let local1 = 1
18+
#^REPEAT_2^#
19+
}
20+
// REPEAT_2-NOT: LocalVar
21+
// REPEAT_2: Decl[LocalVar]/Local: local1[#Int#];
22+
// REPEAT_2-NOT: LocalVar
23+
24+
repeat {
25+
let local1 = 1
26+
repeat {
27+
let local2 = 1
28+
#^REPEAT_3^#
29+
} while true
30+
} while true
31+
// REPEAT_3-NOT: LocalVar
32+
// REPEAT_3: Decl[LocalVar]/Local: local2[#Int#];
33+
// REPEAT_3-NOT: LocalVar
34+
// REPEAT_3: Decl[LocalVar]/Local: local1[#Int#];
35+
// REPEAT_3-NOT: LocalVar
36+
37+
func enclosingFunc1() {
38+
let local0 = 1
39+
repeat {
40+
let local1 = 1
41+
repeat {
42+
let local2 = 1
43+
#^REPEAT_4^#
44+
} while true
45+
} while true
46+
}
47+
// REPEAT_4-NOT: LocalVar
48+
// REPEAT_4: Decl[LocalVar]/Local: local2[#Int#];
49+
// REPEAT_4-NOT: LocalVar
50+
// REPEAT_4: Decl[LocalVar]/Local: local1[#Int#];
51+
// REPEAT_4-NOT: LocalVar
52+
// REPEAT_4: Decl[LocalVar]/Local: local0[#Int#];
53+
// REPEAT_4-NOT: LocalVar
54+
55+
repeat {
56+
let local1 = 1
57+
#^REPEAT_5^#
58+
} while
59+
// REPEAT_5-NOT: LocalVar
60+
// REPEAT_5: Decl[LocalVar]/Local: local1[#Int#];
61+
// REPEAT_5-NOT: LocalVar
62+
63+
repeat {
64+
let local1 = 1
65+
repeat {
66+
let local2 = 1
67+
} while #^REPEAT_COND_1^#
68+
}
69+
// REPEAT_COND_1-NOT: LocalVar
70+
// REPEAT_COND_1: Decl[LocalVar]/Local: local1[#Int#];
71+
// REPEAT_COND_1-NOT: LocalVar

0 commit comments

Comments
 (0)