i have a @rethrows protocol that looks like this:
@rethrows
protocol P
{
func required() throws
}
struct Nonthrowing:P
{
func required()
{
}
}
struct Throwing:P
{
func required() throws
{
}
}
i also have a rethrows functional API that looks like:
func `do`(something:() throws -> ()) rethrows
{
try something()
}
i can use it with a closure literal:
func test(_ conformer:some P) rethrows
{
try `do` { try conformer.required() }
}
but for some reason i cannot pass the method itself, even though this should be equivalent:
func test(_ conformer:some P) rethrows
{
try `do`(something: conformer.required)
}
error: call can throw, but the error is not handled; a function declared 'rethrows' may only throw if its parameter does
try `do`(something: conformer.required)
^
rethrows.swift:27:35: note: call is to 'rethrows' function, but argument function can throw
try `do`(something: conformer.required)
^
why?
3 Likes