You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-7081 "Switch must be exhaustive" when it actually is
relates to:
SR-766 Switch doesn't need to cover negative Int cases
Issue Description:
Switching over an integer type seems to get flagged as not being exhaustive, even if it is. For example, the following switch will generate an error for not being exhaustive:
funcdoSomething(byte: UInt8) {
switchbyte {
caseUInt8.min...UInt8.max:
print("How could this not be exhaustive?")
}
}
The text was updated successfully, but these errors were encountered:
This is an area of Switch statement analysis I really want to be able to cover at some point. I just have no idea how to efficiently represent this for the different kinds of integers Swift supports. It seems like we need some kind of bounded Index Set type for this.
Unfortunately, integer operations like '...' and '<' are just plain functions to Swift, so it'd be difficult to do this kind of analysis. Even with special case understanding of integer intervals, I think there are still cases in the full generality of pattern matching for which exhaustiveness matching would be undecidable. We may eventually be able to handle some cases, but there will always be special cases involved in doing so.
We're unlikely to special-case this given that matching the entire integer space is not a very common thing to do.
Environment
Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)
Additional Detail from JIRA
md5: c7872aebfaa1b675af0c385589a85dfd
is duplicated by:
relates to:
Issue Description:
Switching over an integer type seems to get flagged as not being exhaustive, even if it is. For example, the following switch will generate an error for not being exhaustive:
The text was updated successfully, but these errors were encountered: