Skip to content

Commit c5d0916

Browse files
committed
[BuildTransform] Fix walkExplicitReturnStmts to walk implicit statements
Some statements introduce implicit braces and other things, `walkExplicitReturnStmts` cannot ignore that while trying to find explicit returns. Resolves: rdar://139235128
1 parent 229ca24 commit c5d0916

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,12 +1260,8 @@ static bool walkExplicitReturnStmts(const BraceStmt *BS,
12601260
}
12611261

12621262
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override {
1263-
if (S->isImplicit()) {
1264-
return Action::SkipNode(S);
1265-
}
1266-
12671263
auto *returnStmt = dyn_cast<ReturnStmt>(S);
1268-
if (!returnStmt) {
1264+
if (!returnStmt || returnStmt->isImplicit()) {
12691265
return Action::Continue(S);
12701266
}
12711267

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
@resultBuilder
4+
struct Builder {
5+
static func buildExpression<T: BinaryInteger>(_: T) {}
6+
static func buildBlock<T>(_: T) {}
7+
}
8+
9+
enum E {
10+
case a(Int)
11+
}
12+
13+
protocol Test {
14+
associatedtype V: BinaryInteger
15+
@Builder var prop: V { get }
16+
}
17+
18+
struct S : Test {
19+
var flag: E
20+
21+
var prop: some BinaryInteger {
22+
switch flag {
23+
case .a:
24+
test()
25+
return 42
26+
}
27+
}
28+
29+
func test() {}
30+
}

0 commit comments

Comments
 (0)