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
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
enumEnumExample{case caseA, caseB
}letenumInstance:EnumExample=.a
switch enumInstance {case.caseA:print("it's a")case.caseB:
fallthrough
@unknowndefault: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)
Steps to Reproduce
copy the code above in a empty .swift file
make said file executable (if you want to run it) by running $ chmod +x YOURFILENAME.swift
run $ swiftlint
Expected Results
no no_fallthrough_only warning
Actual Results
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! 🤗
The text was updated successfully, but these errors were encountered:
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:
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:Steps to Reproduce
.swift
file$ chmod +x YOURFILENAME.swift
$ swiftlint
Expected Results
no
no_fallthrough_only
warningActual Results
no_fallthrough_only
warningI 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! 🤗
The text was updated successfully, but these errors were encountered: