I'm trying to merge errors in to generics. And I'm getting two kind's of warning that I can't understand
enum NoThrow: Error {
}
func howToThrow() throws(NoThrow) {
}
func foo() {
do {
try howToThrow()
} catch {
//Constant 'error' inferred to have type 'NoThrow', which is an enum with no cases
//Add an explicit type annotation to silence this warning
switch error {
@unknown default:
fatalError()
}
}
}
Above code is complaining Constant 'error' inferred to have type 'NoThrow', which is an enum with no cases. Add an explicit type annotation to silence this warning
How can I add explicit type mark in this case?
enum EitherError<First:Error,Second:Error>:Error {
case first(First)
case second(Second)
}
func checkTwo<First:Error, Second:Error>(
first: () throws(First) -> Void,
second: () throws(Second) -> Void
) throws(EitherError<First,Second>) {
do {
try first()
} catch {
throw .first(error)
}
do {
try second()
} catch {
throw .second(error)
}
}
func foo() {
do {
try checkTwo(first: {}, second: {})
} catch {
///Switch covers known cases, but 'EitherError<Never, Never>' may have additional unknown values; this is an error in the Swift 6 language mode
///Add missing cases
switch error {
case .first(let never):
break
case .second(let never):
break
@unknown default:
fatalError()
}
}
}
Above Code is yelling at me Switch covers known cases, but 'EitherError<Never, Never>' may have additional unknown values; this is an error in the Swift 6 language mode. Add missing cases
.