I might misunderstand here something. I still don't see why @autoclosure
should not be able to capture whole statements.
// everyone knows that @autoclosure will wrap everything into a block / closure
throw myError ---> { throw myError }
We already can use the closure syntax without @autoclosure
and get the expected result. All we want to achieve here is to make it a bit more convenient and implicit.
And if we're at it, I think it might be a great idea to introduce a tiny breaking change to the language for Swift 6:
let foo = {
throw MyError.bar
}
// currently: `foo: () throws -> Void`
// after: `foo: () throws -> Never`
// If the compiler knows that every exit path of a function throws
// the function itself should never return, hence `Never`
let bar: () throws -> Void = {
if someCondition {
print("swift")
} else {
throw MyError.bar
}
}
I move the last idea into its own pitch. ;)