Skip to content

Commit e64ec00

Browse files
committed
[CodeCompletion] Fix issue in which parts of a result builder were incorrectly skipped
`getLoc` does not necesarrily return the start location of the location (e.g. for `a.b().c()` it returns the location of `c` because that’s the location of the call). But we used the location from `getLoc` as the start location of the synthesized `buildExpression` call. In the added test case, this means that the `buildExpression` call only contained `everlay() {}` and not the code completion token. We thus infered that we could skip it the entire `MyStack {}.pnTabGesture {}.everlay() {}` call for code completion, which isn’t correct. rdar://120798355
1 parent a3ed8cc commit e64ec00

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ class ResultBuilderTransform
227227
buildBlockArguments);
228228
}
229229
if (builder.supports(ctx.Id_buildExpression)) {
230-
expr = builder.buildCall(expr->getLoc(), ctx.Id_buildExpression, {expr},
231-
{Identifier()});
230+
expr = builder.buildCall(expr->getStartLoc(), ctx.Id_buildExpression,
231+
{expr}, {Identifier()});
232232
}
233233

234234
if (isa<CodeCompletionExpr>(expr)) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
3+
4+
func test() {
5+
MyStack {
6+
MyStack {
7+
}
8+
.pnTapGesture {
9+
#^COMPLETE^#
10+
}
11+
.everlay() {
12+
}
13+
}
14+
}
15+
16+
struct MyView {
17+
func everlay(content: () -> Void) -> MyView { MyView() }
18+
}
19+
20+
struct MyStack {
21+
init(@WiewBuilder content: () -> MyView) {}
22+
func pnTapGesture(perform action: () -> Void) -> MyView { MyView() }
23+
}
24+
25+
@resultBuilder
26+
struct WiewBuilder {
27+
static func buildExpression(_ content: MyView) -> MyView { content }
28+
static func buildBlock(_ content: MyView) -> MyView { content }
29+
static func buildBlock() -> MyView { MyView() }
30+
}
31+
32+
// COMPLETE: Decl[FreeFunction]/CurrModule: test()[#Void#]

0 commit comments

Comments
 (0)