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
We can match a optional value against a optional and non-optional expression, but the compiler does not detect “equivalent” cases:
letx: Int? = 1switchx {
case1: print("one")
case .some(1): print("some one") // This is never executed.default: print("default")
}
case .some(1): is never executed, but the compiler does not emit a warning. It would be an improvement if the compiler would emit a “... is already handled by previous pattern ...” warning.
Tested with Xcode 9.3.1, with both the default toolchain and the Swift 4.2 snapshot from May 20, 2018.
Additional Detail from JIRA
md5: a14fa8ad7b92cee9b59d80b0566f8aad
Issue Description:
We can match a optional value against a optional and non-optional expression, but the compiler does not detect “equivalent” cases:
case .some(1):
is never executed, but the compiler does not emit a warning. It would be an improvement if the compiler would emit a “... is already handled by previous pattern ...” warning.Tested with Xcode 9.3.1, with both the default toolchain and the Swift 4.2 snapshot from May 20, 2018.
Related discussion in the Swift forum: Matching optionals in a switch statement
The text was updated successfully, but these errors were encountered: