> On May 16, 2017, at 5:50 PM, Jordan Rose via swift-evolution
> <[email protected]> wrote:
>
>>
>> On May 16, 2017, at 17:37, John McCall <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> I'm not sure what you're proposing to disallow here. I don't think we
>> should add any extra restrictions in order to avoid problems with
>> unfortunate uses of withoutActuallyEscaping, though.
>
> Here's a small, currently-legal, re-entrant case that only calls the wrapped
> function once.
>
> var global: (() -> Void)?
> func problem(_ fn: () -> Void) {
> withoutActuallyEscaping(fn) { wrappedFn in
> global = wrappedFn
> fn() // note: not wrappedFn
> }
> }
> func test() {
> var local = 0
> problem() {
> local += 1
> if let callback = global {
> global = nil
> callback()
> }
> print(local)
> }
> }
> test()
>
> We could prevent this by saying it's not legal to refer to 'fn' inside the
> callback for withoutActuallyEscaping, and you have to use 'wrappedFn' instead.
This rule seems quite reasonable to me and possible to check statically. It is
only feasible to enforce the rule statically when the closure passed to the
‘do’ argument of withoutActuallyEscaping(_:do:) hasn’t itself escaped — but
since ‘fn’ here is noescape it can’t be referred to inside a closure that
escapes.
Devin
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution