Skip to content

[5.8][BuilderTransform] Make sure that synthesized if elements have corr… #62970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Sema/BuilderTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ class ResultBuilderTransform
// The operand should have optional type if we had optional results,
// so we just need to call `buildIf` now, since we're at the top level.
if (isOptional && isTopLevel(anchor)) {
builderCall = buildCallIfWanted(ifStmt->getEndLoc(),
builderCall = buildCallIfWanted(ifStmt->getThenStmt()->getStartLoc(),
builder.getBuildOptionalId(),
builderCall, /*argLabels=*/{});
}
Expand Down Expand Up @@ -1304,7 +1304,7 @@ class ResultBuilderTransform
/*argLabels=*/{}));
}

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

Expand Down
23 changes: 23 additions & 0 deletions test/SourceKit/Sema/issue62848.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %sourcekitd-test -req=collect-type %s -- %s

struct Rectangle {
init() {}
}

@resultBuilder public struct WiewBuilder {
public static func buildBlock<Content>(_ content: Content) -> Content {
return content
}
public static func buildIf<Content>(_ content: Content?) -> Content? {
return content
}
}

public struct AStack<Content> {
init(@WiewBuilder content: () -> Content) {}
}

func foo() {
AStack {
if true {
Rectangle()