|
1 |
| -// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-library-evolution |
2 |
| -// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-library-evolution -enable-nonfrozen-enum-exhaustivity-diagnostics |
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution %S/Inputs/exhaustive_switch_testable_helper.swift -emit-module -o %t |
| 3 | +// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-library-evolution -I %t |
| 4 | +// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-library-evolution -enable-nonfrozen-enum-exhaustivity-diagnostics -I %t |
| 5 | + |
| 6 | +import exhaustive_switch_testable_helper |
3 | 7 |
|
4 | 8 | func foo(a: Int?, b: Int?) -> Int {
|
5 | 9 | switch (a, b) {
|
@@ -1214,6 +1218,54 @@ func sr11160_extra() {
|
1214 | 1218 | }
|
1215 | 1219 | }
|
1216 | 1220 |
|
| 1221 | +public enum SR11672Tests { |
| 1222 | + |
| 1223 | + @frozen public enum FrozenSameModule { |
| 1224 | + case a, b |
| 1225 | + } |
| 1226 | + |
| 1227 | + func testNotRequired(_ value: NonExhaustive, _ value2: FrozenEnum, _ value3: FrozenSameModule) { |
| 1228 | + switch value { |
| 1229 | + // expected-error@-1 {{switch must be exhaustive}} |
| 1230 | + // expected-note@-2 {{add missing case: '.a'}} |
| 1231 | + // expected-note@-3 {{add missing case: '.b'}} |
| 1232 | + // Do not suggest adding '@unknown default' |
| 1233 | + } |
| 1234 | + |
| 1235 | + switch value2 { |
| 1236 | + // expected-error@-1 {{switch must be exhaustive}} |
| 1237 | + // expected-note@-2 {{add missing case: '.a'}} |
| 1238 | + // expected-note@-3 {{add missing case: '.b'}} |
| 1239 | + // expected-note@-4 {{add missing case: '.c'}} |
| 1240 | + } |
| 1241 | + |
| 1242 | + switch value3 { |
| 1243 | + // expected-error@-1 {{switch must be exhaustive}} |
| 1244 | + // expected-note@-2 {{add missing case: '.a'}} |
| 1245 | + // expected-note@-3 {{add missing case: '.b'}} |
| 1246 | + } |
| 1247 | + } |
| 1248 | + |
| 1249 | + @inlinable public func testNotRequired2(_ value: FrozenSameModule) { |
| 1250 | + switch value { |
| 1251 | + // expected-error@-1 {{switch must be exhaustive}} |
| 1252 | + // expected-note@-2 {{add missing case: '.a'}} |
| 1253 | + // expected-note@-3 {{add missing case: '.b'}} |
| 1254 | + } |
| 1255 | + } |
| 1256 | + |
| 1257 | + // Inlinable code is considered "outside" the module and must include a default |
| 1258 | + // case. |
| 1259 | + @inlinable public func testRequired(_ value: NonExhaustive) { |
| 1260 | + switch value { |
| 1261 | + // expected-error@-1 {{switch must be exhaustive}} |
| 1262 | + // expected-note@-2 {{add missing case: '.a'}} |
| 1263 | + // expected-note@-3 {{add missing case: '.b'}} |
| 1264 | + // expected-note@-4 {{handle unknown values using "@unknown default"}} |
| 1265 | + } |
| 1266 | + } |
| 1267 | +} |
| 1268 | + |
1217 | 1269 | // SR-11212 tests: Some of the tests here rely on compiler bugs related to
|
1218 | 1270 | // implicit (un)tupling in patterns.
|
1219 | 1271 | //
|
|
0 commit comments