Commit Graph

7 Commits

Author SHA1 Message Date
Alex Hoppen
7d7eb6e61d [Sema/IDE] Emit same diagnostics for missing switch cases independent of editor mode 2024-08-12 14:01:22 -07:00
Allan Shortlidge
3acc0d6655 SILGen/Sema: Avoid diagnosing @unknown default switch cases as unreachable.
Suppose you have an exhaustive switch statement which matches all the cases of
a Swift enum defined in a different module named `External`:

```
import External

var e: External.SomeEnum = //...

switch e {
case .a: break
}
```

If `External` is compiled with library evolution and `SomeEnum` is not frozen,
then the compiler will warn:

```
warning: switch covers known cases, but 'SomeEnum' may have additional unknown values
```

You add an `@unknown default` to the switch to resolve this warning. Now
suppose in another build configuration, `External` is built _without_ library
evolution. The compiler will complain about the unreachability of the default
case:

```
warning: Default will never be executed
```

These contradictory compiler diagnostics encourage the developer to change the
code in a way that will cause a diagnostic in the other configuration.
Developers should have the tools to address all warning diagnostics in a
reasonable fashion and this is a case where the compiler makes that especially
difficult. Given that writing `@unknown default` instead of `default` is a very
intentional action that would be the result of addressing the library evolution
configuration, it seems reasonable to suppress the `Default will never be
executed` diagnostic.
2024-03-09 12:26:22 -08:00
Slava Pestov
1159af50d9 Rename -enable-resilience to -enable-library-evolution and make it a driver flag
Fixes <rdar://problem/47679085>.
2019-03-14 22:24:26 -04:00
Robert Widmann
2fb5afb755 Remove the @_downgrade_exhaustivity_check hack
This hack was only needed for Swift 3 mode in a narrow case.  Flush it out of the compiler so we can simplify the space engine.
2018-08-24 10:54:43 -07:00
Jordan Rose
7c689c322e Prefer @unknown default over @unknown case _ in diagnostics
(and fix-its)
2018-04-05 17:54:49 -07:00
Jordan Rose
2a0f9c3eb0 '@unknown' can match unknown cases in nested positions
That is, when matching non-frozen enums at non-top-level positions:

    switch (nonFrozenEnum1, nonFrozenEnum2) {
    case (.singleKnownCase1, .singleKnownCase2): ...
    unknown: ...
    }

...it's sufficient to use '@unknown' to match

  (.singleKnownCase1, .someFutureCase2)
  (.someFutureCase1, .singleKnownCase2)
  (.someFutureCase1, .someFutureCase2)
2018-04-05 16:35:15 -07:00
Jordan Rose
7ba6ed62b2 Don't require '@unknown' in playgrounds or in the debugger
We still model the enums as non-exhaustive so that someone /can/
handle unknown cases, which may be important for imported enums. But
we won't diagnose a problem if the only missing case is '@unknown'.
2018-04-05 16:35:14 -07:00