To me the this feels like missing the target. Does anyone have an actual use case that would ask for this?
Here is another example that illustrates the issue I think needs addressing:
Image this API:
public enum Temperature {
case cold
case veryCold
// adding this is currently considered a breaking change -> major version
case soColdYourTeethHurt
}
public struct AtTheBar {
public func haveADrink(temperature: Temperature) {}
}
Obviously, if these were separate methods, adding a new one is considered non-breaking (semver minor):
public struct AtTheBar {
public func haveAColdDrink() {}
public func haveAVeryDrink() {}
//added in a minor version
public func haveADrinkSoColdYourTeethHurt() {}
}
Neither of the cases is particularly important or ignorable - and all is fine with the world as long as as nobody exhaustively switches over the enum. But currently we cannot tell a package's user "my friend, this enum is not meant to be exhaustively switched over - things might be added".
Also, nobody would argue "I need a warning when a new function appears in the API, I could miss something".
Return values/errors are just the same but reversed: some enum
s are just meant to be extended over time.
Of course, one does not HAVE to use an enum
- but I think we can all agree that swift's enum
s are a fantastic construct in many cases (pun intended). Without a solution in this space, having an enum
in a public API is punished so hard that people tend to avoid them.