Skip to content

Commit 0ac8cd3

Browse files
committed
Sema: Allow resilient modules to add enum elements without breaking clients.
In the implementation of #73472, warnings about uncovered cases were upgraded to errors in switches covering enums with an `@unknown default` case. This change was a mistake; it should not be source breaking for a resilient library to add new cases to a non-frozen enum. Resolves rdar://138488976.
1 parent 3e2556d commit 0ac8cd3

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

lib/Sema/TypeCheckSwitchStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ namespace {
11881188
case RequiresDefault::UncoveredSwitch: {
11891189
OS << tok::kw_default << ":\n" << placeholder << "\n";
11901190
DE.diagnose(startLoc, mainDiagType.value())
1191-
.warnUntilSwiftVersionIf(downgrade, 6);
1191+
.limitBehaviorIf(downgrade, DiagnosticBehavior::Warning);
11921192
DE.diagnose(startLoc, diag::missing_several_cases, /*default*/true)
11931193
.fixItInsert(insertLoc, buffer.str());
11941194
}
@@ -1208,7 +1208,7 @@ namespace {
12081208
// Check if we still have to emit the main diagnostic.
12091209
if (mainDiagType.has_value()) {
12101210
DE.diagnose(startLoc, mainDiagType.value())
1211-
.warnUntilSwiftVersionIf(downgrade, 6);
1211+
.limitBehaviorIf(downgrade, DiagnosticBehavior::Warning);
12121212
}
12131213

12141214
// Add notes to explain what's missing.

test/Compatibility/exhaustive_switch_swift_6.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,37 @@ func testSwitch() -> Bool {
2929
case (.case8, _): return true
3030
case (.case9, _): return true
3131
case (.case10, _): return true
32+
}
33+
34+
switch (OverlyLargeSpaceEnum.case1, OverlyLargeSpaceEnum.case2) { // expected-warning {{switch must be exhaustive}}
35+
// expected-note@-1 {{add missing case: '(.case11, _)'}}
36+
case (.case0, _): return true
37+
case (.case1, _): return true
38+
case (.case2, _): return true
39+
case (.case3, _): return true
40+
case (.case4, _): return true
41+
case (.case5, _): return true
42+
case (.case6, _): return true
43+
case (.case7, _): return true
44+
case (.case8, _): return true
45+
case (.case9, _): return true
46+
case (.case10, _): return true
3247
@unknown default: return false
3348
}
49+
50+
// No diagnostic
51+
switch (OverlyLargeSpaceEnum.case1, OverlyLargeSpaceEnum.case2) {
52+
case (.case0, _): return true
53+
case (.case1, _): return true
54+
case (.case2, _): return true
55+
case (.case3, _): return true
56+
case (.case4, _): return true
57+
case (.case5, _): return true
58+
case (.case6, _): return true
59+
case (.case7, _): return true
60+
case (.case8, _): return true
61+
case (.case9, _): return true
62+
case (.case10, _): return true
63+
case (.case11, _): return true
64+
}
3465
}

test/FixCode/fixits-switch-nonfrozen.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ public func testNonExhaustive(_ value: NonExhaustive, _ payload: NonExhaustivePa
219219
}
220220

221221
switch value {
222-
// expected-error@-1 {{switch must be exhaustive}}
222+
// expected-warning@-1 {{switch must be exhaustive}}
223223
// expected-note@-2 {{add missing case: '.b'}} {{+4:3-3=case .b:\n<#code#>\n}}
224224
case .a: break
225225
@unknown case _: break
226226
}
227227

228228
switch value {
229-
// expected-error@-1 {{switch must be exhaustive}}
229+
// expected-warning@-1 {{switch must be exhaustive}}
230230
// expected-note@-2 {{add missing case: '.a'}} {{+5:3-3=case .a:\n<#code#>\n}}
231231
// expected-note@-3 {{add missing case: '.b'}} {{+5:3-3=case .b:\n<#code#>\n}}
232232
// expected-note@-4 {{add missing cases}} {{+5:3-3=case .a:\n<#code#>\ncase .b:\n<#code#>\n}}
@@ -350,7 +350,7 @@ public func testNonExhaustive(_ value: NonExhaustive, _ payload: NonExhaustivePa
350350
}
351351

352352
switch payload {
353-
// expected-error@-1 {{switch must be exhaustive}}
353+
// expected-warning@-1 {{switch must be exhaustive}}
354354
// expected-note@-2 {{add missing case: '.b(_)'}} {{+4:3-3=case .b(_):\n<#code#>\n}}
355355
case .a: break
356356
@unknown case _: break
@@ -366,7 +366,7 @@ public func testNonExhaustive(_ value: NonExhaustive, _ payload: NonExhaustivePa
366366
}
367367

368368
switch payload {
369-
// expected-error@-1 {{switch must be exhaustive}}
369+
// expected-warning@-1 {{switch must be exhaustive}}
370370
// expected-note@-2 {{add missing case: '.b(true)'}} {{+5:3-3=case .b(true):\n<#code#>\n}}
371371
case .a: break
372372
case .b(false): break

0 commit comments

Comments
 (0)