Skip to content

Commit 80c4c90

Browse files
authored
Merge pull request #34603 from xedin/rdar-70256351
[ResultBuilders] Account of a fact that re-write of a statement can fail
2 parents 7dd6660 + 1d3f320 commit 80c4c90

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,12 @@ class BuilderClosureRewriter
11581158
stmt,
11591159
ResultBuilderTarget{ResultBuilderTarget::TemporaryVar,
11601160
std::move(captured)});
1161+
1162+
// Re-write of statements that envolve type-checking
1163+
// could fail, such a failure terminates the walk.
1164+
if (!finalStmt)
1165+
return nullptr;
1166+
11611167
newElements.push_back(finalStmt);
11621168
continue;
11631169
}
@@ -1512,7 +1518,7 @@ BraceStmt *swift::applyResultBuilderTransform(
15121518
rewriteTarget) {
15131519
BuilderClosureRewriter rewriter(solution, dc, applied, rewriteTarget);
15141520
auto captured = rewriter.takeCapturedStmt(body);
1515-
return cast<BraceStmt>(
1521+
return cast_or_null<BraceStmt>(
15161522
rewriter.visitBraceStmt(
15171523
body,
15181524
ResultBuilderTarget::forReturn(applied.returnExpr),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-typecheck-verify-swift -target x86_64-apple-macosx10.15 -swift-version 5
2+
// REQUIRES: objc_interop
3+
// REQUIRES: OS=macosx
4+
5+
import SwiftUI
6+
7+
struct ContentView: View {
8+
@State private var currentPage = "1"
9+
10+
var body: some View {
11+
switch currentPage {
12+
case 1: // expected-error {{expression pattern of type 'Int' cannot match values of type 'String'}}
13+
// expected-note@-1 {{overloads for '~=' exist with these partially matching parameter lists: (Substring, String)}}
14+
Text("1")
15+
default:
16+
Text("default")
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)