<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I implemented a better (i.e. correct) diagnostic message for this at <a href="https://github.com/apple/swift/pull/4670" class="">https://github.com/apple/swift/pull/4670</a>. I want to also do a better diagnostic specifically for aggregate parameters to functions (e.g. optional closures), but that requires more work in the type checker.</div><div class=""><br class=""></div><div class="">Basically, @escaping is valid only on closures in function parameter position. The noescape-by-default rule only applies to these closures at function parameter position, otherwise they are escaping. Aggregates, such as enums with associated values (e.g. Optional), tuples, structs, etc., if they have closures, follow the default rules for closures that are not at function parameter position, i.e. they are escaping.</div><div class=""><br class=""></div><div class="">It would be a post-Swift-3 addition to the language to be able to support more robust liveness tracking here. There may be interesting directions to take this, with optional closures being the most common beneficiary. </div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Sep 7, 2016, at 3:33 PM, Shawn Erickson via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I see <a href="https://bugs.swift.org/browse/SR-2324" class="">https://bugs.swift.org/browse/SR-2324</a> and <a href="https://bugs.swift.org/browse/SR-2444" class="">https://bugs.swift.org/browse/SR-2444</a> which looks related to this issue and may explain the error I saw on "the other side" of this.<div class=""><br class=""></div><div class=""><br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Sep 7, 2016 at 3:28 PM Shawn Erickson <<a href="mailto:shawnce@gmail.com" class="">shawnce@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Yeah I actually have a few of those myself that I can no longer do.</div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Sep 7, 2016 at 3:26 PM Jon Shier <<a href="mailto:jon@jonshier.com" target="_blank" class="">jon@jonshier.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Perhaps relatedly, it no longer seems possible to mark typealiased closures as @escaping. That was quite handy when you know that closures will always be used asynchronously.<div class=""><br class=""></div><div class=""><br class=""></div><div class="">Jon</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""></blockquote></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Sep 7, 2016, at 6:15 PM, Shawn Erickson via swift-users <<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>> wrote:</div><br class=""></blockquote></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">I should note that this issue also appeared in an earlier variant of Swift after the addition of @escaping but I was on vacation so didn't get a chance to report it then. It isn't new with the Xcode 8 GM.<br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Sep 7, 2016 at 3:08 PM Shawn Erickson <<a href="mailto:shawnce@gmail.com" target="_blank" class="">shawnce@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">I like and fully supported the change to @escaping away from @noescape however in a body of code that I am porting to the latest Swift 3 variant (as found in Xcode 8 GM) I am hitting an issue for methods that take an optional completion closure. If optional is involved I can't find a way to apply @escape to the escaping closure. See the following for an basic example...<div class=""><br class=""></div><div class="">Is their a way to do what I need and/or is this an edge case in the implementation of @escaping?<br class=""><div class=""><br class=""></div><div class=""><div class=""><font face="monospace" size="1" class="">typealias MyCallback = (String)->()</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Happy</font></div><div class=""><font face="monospace" size="1" class="">func foo1(bar: String, completion: ((String)->())) {</font></div><div class=""><font face="monospace" size="1" class=""> completion(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Happy</font></div><div class=""><font face="monospace" size="1" class="">func foo2(bar: String, completion: MyCallback) {</font></div><div class=""><font face="monospace" size="1" class=""> completion(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Happy</font></div><div class=""><font face="monospace" size="1" class="">func foo3(bar: String, completion: ((String)->())? = nil) {</font></div><div class=""><font face="monospace" size="1" class=""> completion?(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Happy</font></div><div class=""><font face="monospace" size="1" class="">func foo4(bar: String, completion: MyCallback? = nil) {</font></div><div class=""><font face="monospace" size="1" class=""> completion?(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Happy</font></div><div class=""><font face="monospace" size="1" class="">func foo5(bar: String, completion: Optional<MyCallback> = nil) {</font></div><div class=""><font face="monospace" size="1" class=""> completion?(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Happy</font></div><div class=""><font face="monospace" size="1" class="">func foo6(bar: String, completion: @escaping (String)->()) {</font></div><div class=""><font face="monospace" size="1" class=""> completion(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Happy</font></div><div class=""><font face="monospace" size="1" class="">func foo7(bar: String, completion: @escaping MyCallback) {</font></div><div class=""><font face="monospace" size="1" class=""> completion(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Unhappy...</font></div><div class=""><font face="monospace" size="1" class="">// "@escaping attribute only applies to function types"</font></div><div class=""><font face="monospace" size="1" class="">func foo8(bar: String, completion: @escaping ((String)->())? = nil) {</font></div><div class=""><font face="monospace" size="1" class=""> completion?(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Unhappy...</font></div><div class=""><font face="monospace" size="1" class="">// "@escaping attribute only applies to function types"</font></div><div class=""><font face="monospace" size="1" class="">func foo9(bar: String, completion: @escaping MyCallback? = nil) {</font></div><div class=""><font face="monospace" size="1" class=""> completion?(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Unhappy...</font></div><div class=""><font face="monospace" size="1" class="">// "@escaping attribute only applies to function types"</font></div><div class=""><font face="monospace" size="1" class="">func foo10(bar: String, completion: (@escaping ((String)->()))? = nil) {</font></div><div class=""><font face="monospace" size="1" class=""> completion?(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Unhappy...</font></div><div class=""><font face="monospace" size="1" class="">// "@escaping attribute only applies to function types"</font></div><div class=""><font face="monospace" size="1" class="">func foo11(bar: String, completion: (@escaping MyCallback)? = nil) {</font></div><div class=""><font face="monospace" size="1" class=""> completion?(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div><div class=""><font face="monospace" size="1" class=""><br class=""></font></div><div class=""><font face="monospace" size="1" class="">// Unhappy...</font></div><div class=""><font face="monospace" size="1" class="">// "@escaping attribute only applies to function types"</font></div><div class=""><font face="monospace" size="1" class="">func foo12(bar: String, completion: Optional<@escaping MyCallback> = nil) {</font></div><div class=""><font face="monospace" size="1" class=""> completion?(bar)</font></div><div class=""><font face="monospace" size="1" class="">}</font></div></div></div></div></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div></blockquote></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>