I have a function which looks something like this:
func test(closure: () -> ()) {
let localClosure = { closure() }
localClosure()
}
This is only an example and does not fully reflect the problem I encountered, obviously here I could have just called closure
directly!
It should be clear that in the above code, closure
cannot escape. However, I get the error:
Closure use of non-escaping parameter 'closure' may allow it to escape
Now, if localClosure
was escaping in some way, I'd understand this error, but it doesn't escape. I even tried annotating localClosure
as @noescape
(even though that attribute is deprecated in Swift 3), and according to the warning I got:
@noescape is the default and is deprecated
If localClosure
is, by default, non-escaping, then why can't another non-escaping closure go inside it? Or is this a bug/limitation of the compiler?