Skip to content

Commit 09ae4f5

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 acf4e28 commit 09ae4f5

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Diff for: lib/Sema/BuilderTransform.cpp

+2-2
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)) {

Diff for: validation-test/IDE/issues_fixed/rdar120798355.swift

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %batch-code-completion
2+
3+
func test() {
4+
MyStack {
5+
MyStack {
6+
}
7+
.pnTapGesture {
8+
#^COMPLETE^#
9+
}
10+
.everlay() {
11+
}
12+
}
13+
}
14+
15+
struct MyView {
16+
func everlay(content: () -> Void) -> MyView { MyView() }
17+
}
18+
19+
struct MyStack {
20+
init(@WiewBuilder content: () -> MyView) {}
21+
func pnTapGesture(perform action: () -> Void) -> MyView { MyView() }
22+
}
23+
24+
@resultBuilder
25+
struct WiewBuilder {
26+
static func buildExpression(_ content: MyView) -> MyView { content }
27+
static func buildBlock(_ content: MyView) -> MyView { content }
28+
static func buildBlock() -> MyView { MyView() }
29+
}
30+
31+
// COMPLETE: Decl[FreeFunction]/CurrModule: test()[#Void#]

0 commit comments

Comments
 (0)