[swift-evolution] Should explicit `self.` be required when providing method as closure?

Anton Zhilin antonyzhilin at gmail.com
Sat Mar 4 03:45:29 CST 2017


I disagree with dropping function references in general, but I do agree
with limiting partially applied method references.

In @escaping arguments, adding self. won’t add enough evidence that it
actually creates a closure with capture.
Even in non-escaping context, I find plain method references odd:

func square(_ x: Int) -> Int { … }

(1...10).map(square)  // totally ok with that
class SomeClass {
    func foo(_ x: Int) -> Int { … }

    func bar() {
        (1...10).map(foo)       // what??
        (1...10).map(self.foo)  // ok
        someControl.addHandler(self.foo)  // should be error if @escaping?
    }
}

2017-03-04 10:09 GMT+03:00 David Hart via swift-evolution <
swift-evolution at swift.org>:

I encountered this precise memory leak in my code a few days ago, so I
> sympathize. A second solution would be to drop function references. I think
> a core team member suggested it on another thread.

​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170304/633c961c/attachment.html>


More information about the swift-evolution mailing list