In swift 4.2 and later we can use @unknown default
in a switch block case to handle _future_ enum cases.
This is ok however, as far as I know, this case has to be handled separately from other cases in a switch.
Let's say that we have the following script:
#!/usr/bin/swift
import Foundation
enum EnumExample {
case caseA, caseB
}
let enumInstance: EnumExample = .a
switch enumInstance {
case .caseA:
print("it's a")
case .caseB:
fallthrough
@unknown default:
print("it's not a")
}
This works as expected, however, again, as far as I know, there's no way to merge the cases case .caseB:
and @unknown default:
.
As the latest SwiftLint version (0.31.0), this code triggers the no_fallthrough_only
warning:
warning: No Fallthrough Only Violation: Fallthroughs can only be used if the `case` contains at least one other statement. (no_fallthrough_only)
.swift
file$ chmod +x YOURFILENAME.swift
$ swiftlint
no no_fallthrough_only
warning
no_fallthrough_only
warning
I understand why the warning triggers, however I believe this case where we use @unknown default
should be an exception to this rule.
Thank you in advance for all the support! 馃
Running into this same scenario, would greatly appreciate the proposed exception!
Perhaps we could/should silence violations that fall through to an @unknown default
case?
Perhaps we could/should silence violations that fall through to an
@unknown default
case?
@jpsim I鈥檇 be ok with that 馃槉
Most helpful comment
Perhaps we could/should silence violations that fall through to an
@unknown default
case?