File tree Expand file tree Collapse file tree 2 files changed +41
-13
lines changed Expand file tree Collapse file tree 2 files changed +41
-13
lines changed Original file line number Diff line number Diff line change @@ -630,19 +630,6 @@ class ResultBuilderTransform
630
630
transformCase (CaseStmt *caseStmt) {
631
631
auto *body = caseStmt->getBody ();
632
632
633
- // Explicitly disallow `case` statements with empty bodies
634
- // since that helps to diagnose other issues with switch
635
- // statements by excluding invalid cases.
636
- if (auto *BS = dyn_cast<BraceStmt>(body)) {
637
- if (BS->getNumElements () == 0 ) {
638
- // HACK: still allow empty bodies if typechecking for code
639
- // completion. Code completion ignores diagnostics
640
- // and won't get any types if we fail.
641
- if (!ctx.SourceMgr .hasIDEInspectionTargetBuffer ())
642
- return std::nullopt;
643
- }
644
- }
645
-
646
633
NullablePtr<Expr> caseVarRef;
647
634
std::optional<UnsupportedElt> unsupported;
648
635
SmallVector<ASTNode, 4 > newBody;
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-emit-silgen %s -verify | %FileCheck %s
2
+
3
+ // Tests for a crash that occurred when the result builder transform encountered
4
+ // an empty case statement.
5
+ protocol V { }
6
+
7
+ struct EV : V { }
8
+
9
+ @resultBuilder
10
+ struct VB {
11
+ static func buildBlock( _ components: any V ... ) -> any V { EV ( ) }
12
+ static func buildEither( first: any V ) -> any V { first }
13
+ static func buildEither( second: any V ) -> any V { second }
14
+ }
15
+
16
+ extension String : V { }
17
+
18
+ enum E {
19
+ case a( Int )
20
+ case b( String )
21
+ }
22
+
23
+ struct S {
24
+ var flag : E
25
+
26
+ // CHECK-LABEL: sil hidden [ossa] @$s25result_builder_empty_case1SV4testAA1V_pyF
27
+ // CHECK: switch_enum
28
+ @VB
29
+ func test( ) -> any V {
30
+ switch flag {
31
+ case . a:
32
+ // When NOT_DEFINED is... not defined... this ends up being an empty case.
33
+ // We permit this
34
+ #if NOT_DEFINED
35
+ EV ( )
36
+ #endif
37
+ case . b:
38
+ EV ( )
39
+ }
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments