<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I believe it has been made clear upthread now, but only the closure is capturing self. Your evil function only stores a copy of the dictionary. </div><div class=""><br class=""></div><div class="">This behavior is identical whether you use [strong self] and metadata or you use self.metadata so I don’t understand why it would be an argument against the proposal. Either way the capture of self by the closure is explicitly represented in the code where it happens. [strong self] actually seems a bit more clear to me.</div><div class=""><br class=""></div><div class="">An example that behaves like you stated could be concocted if we modify your example to pass a bound method rather than a property value, however that seems pretty unlikely to happen unintentionally even if / when we can obtain references to bound property getters / setters.</div><div class=""><br class=""></div><div class=""><div class=""><span style="font-family: HelveticaNeue;" class="">typealias evilArg = [String:String]</span></div><div class="">var strongReference: () -> evilArg<br class="">func evil(foo: () -> evilArg ) {<br class=""> strongReference = foo<br class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">}</div><div class=""><br class=""></div><div class="">final class Photo {<br class=""> var data = [UInt8](count: 100000000, repeatedValue: 0) //a large amount of data<br class=""> func metadata() -> [String: String] { return [:] }<br class=""> func save() {<br class=""> dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)) {<br class=""> evil(self.metadata)<br class=""> }<br class=""> }<br class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">}</div></div></div></div></div></div></div></div><div class=""><br class=""></div><div class="">I understand why you’re afraid of anything that might lead to unintentionally storing a strong reference or creating a reference cycle. I don’t understand why this proposal is likely to make that happen. I would even argue it might make it less likely to happen. If developers get in the habit of using the capture list rather than explicitly using “self.” in the body they will be more likely to capture only what they need. In your example the developer may have specified [metadata = self.metadata] rather than using [strong self] if the metadata value at the time of closure capture was sufficient.</div><div class=""><br class=""></div><div class="">Matthew</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 15, 2015, at 7:23 PM, Drew Crawford via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 15, 2015, at 7:15 PM, Greg Parker <<a href="mailto:gparker@apple.com" class="">gparker@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: HelveticaNeue; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">We could make it more difficult for unaware programmers to *write* the `[strong self]` version, at least. When a programmer writes just `metadata` in a closure, the compiler could continue to suggest using `self.metadata` and not suggest using `[strong self]`.</span></div></blockquote></div><br class=""><div class="">That's not (especially) the danger I'm worried about.</div><div class=""><br class=""></div><div class="">I'm worried about the case where I write `[strong self] in` and then years later I add the `evil(f)` to the bottom of the closure, because it turns out we need more code in there.</div><div class=""><br class=""></div><div class="">I'm also worried about the case where I write nonEvil(f) but at some later time the implementation of nonEvil(f) becomes evil.</div><div class=""><br class=""></div><div class="">I'm also worried about the case where nonEvil(f) is a call into closed-source UIKit and without any visibility to me, UIKit's implementation of nonEvil becomes evil between iOS10b3 and iOS10b4.</div><div class=""><br class=""></div><div class="">These things are "category 5" bugs waiting to happen, and they can't be competently addressed with a UI-level fix in Xcode.</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAcWRvrKJiA0Q-2FRIpXY8-2B503kAOGN-2B9XG2PlniO9WFb2Q7QEqJVC04Bo5Ogu5HSavR-2FkXcnfJ3VP1CpB7uYILkfTQ3cMXUMYveFmskLKIiZg5A0eYsQvB-2BpT2i8593bus-2Fem0QOkd23pkhmoGsw4VPDpYAm1-2FrpPLdGAuw1cLJAaFIWCGpWuAW5HmC6vKdAL-2Fqs-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>