Compiler cannot infer rethrow error type when calling rethrows function inside throws(e)
The rethrows telling us “Error type thrown is the same passed closure throws”.
But in this simplified example in some reason it cannot infer that body error type is exact, not any Error.
What I’m missing?
Are there suggestions on using rethrows functions (like DispatchQueue.sync) inside typed-throw ones.
If E is inferred to be Never, you don't need try at call site, in effect making both of them non-throwing, when passing a non-throwing argument. Is this not working for you?
I believe this is because rethrows doesn’t technically require that the error thrown is the same error the closure threw, just that the error is not thrown if the closure doesn’t throw. In other words, this is legal: