Skip to content

Commit bc267f9

Browse files
authored
Merge pull request #62950 from xedin/issue-62848
[BuilderTransform] Make sure that synthesized `if` elements have corr…
2 parents 5d9c629 + 945f35f commit bc267f9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ class ResultBuilderTransform
12751275
// The operand should have optional type if we had optional results,
12761276
// so we just need to call `buildIf` now, since we're at the top level.
12771277
if (isOptional && isTopLevel(anchor)) {
1278-
builderCall = buildCallIfWanted(ifStmt->getEndLoc(),
1278+
builderCall = buildCallIfWanted(ifStmt->getThenStmt()->getStartLoc(),
12791279
builder.getBuildOptionalId(),
12801280
builderCall, /*argLabels=*/{});
12811281
}
@@ -1304,7 +1304,7 @@ class ResultBuilderTransform
13041304
/*argLabels=*/{}));
13051305
}
13061306

1307-
auto *ifVarRef = builder.buildVarRef(ifVar.get(), ifStmt->getEndLoc());
1307+
auto *ifVarRef = builder.buildVarRef(ifVar.get(), ifStmt->getStartLoc());
13081308
doBody.push_back(TypeJoinExpr::create(ctx, ifVarRef, buildEitherCalls));
13091309
}
13101310

test/SourceKit/Sema/issue62848.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %sourcekitd-test -req=collect-type %s -- %s
2+
3+
struct Rectangle {
4+
init() {}
5+
}
6+
7+
@resultBuilder public struct WiewBuilder {
8+
public static func buildBlock<Content>(_ content: Content) -> Content {
9+
return content
10+
}
11+
public static func buildIf<Content>(_ content: Content?) -> Content? {
12+
return content
13+
}
14+
}
15+
16+
public struct AStack<Content> {
17+
init(@WiewBuilder content: () -> Content) {}
18+
}
19+
20+
func foo() {
21+
AStack {
22+
if true {
23+
Rectangle()

0 commit comments

Comments
 (0)