<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="">AFAIK, fix-it is driven by the Swift compiler/source kit.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 13 juil. 2017 à 23:17, Saagar Jha via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">You should probably file a Radar for this, since Xcode isn’t part of the Swift project.<div class=""><br class=""><div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>
</div>
<div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jul 13, 2017, at 19:46, iCloud 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="">
<title class=""></title>
<div class="">
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">Hi Swift community,
<div class=""><br class=""></div>
<div class="">I was wondering if we have considered adding support for providing Xcode automatic fix-it’s for closures being returned from a function.</div>
<div class=""><br class=""></div>
<div class="">For example, here is an incorrect version of a function that requires two `@escaping` keywords to be inserted.</div>
<div class=""><br class=""></div>
<div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span> <span style="font-variant-ligatures: no-common-ligatures" class="">mapping <A, B, C> (f:</span> <span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">B</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) -></span> <span style="font-variant-ligatures: no-common-ligatures" class="">((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">B</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) -> ((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">))</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div>
</div>
<div class="">Despite the complexity, the compiler manages to catch two errors.</div>
<div class=""><br class=""></div>
<div class="">1. Closure use of non-escaping parameter `f` may allow it to escape</div>
<div class=""> a. Automatic Fix-it by doing `f: @escaping (A) - > (B)`<br class=""></div>
<div class=""><br class=""></div>
<div class="">2. Closure use of non-escaping parameter `reducer` may allow it to escape</div>
<div class=""> b. No Fix-it provided <———— <br class=""></div>
<div class=""><br class=""></div>
<div class="">As you see above, the two places where a compile-time error occurred had the same exact problem; they both needed a `@escaping`. However, while the function parameter was offered an automatic fix-it, the nested closure being returned was not.</div>
<div class=""><br class=""></div>
<div class="">
<div class="">Here’s the correct version of the function.</div>
<div class=""><br class=""></div>
<div class="">
<div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span> <span style="font-variant-ligatures: no-common-ligatures" class="">mapping <A, B, C> (f:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">@escaping</span> <span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">B</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) -> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">@escaping</span> <span style="font-variant-ligatures: no-common-ligatures" class="">((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">B</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">))) -> ((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures" class="">{ reducer</span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures" class="">{ accum, input</span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> reducer(accum, f(input))</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div>
</div>
</div>
</div>
<div class="">I know this is a small feature for a very specific use case but I think it could help make Xcode a little smarter :D </div>
<div class="">Thanks for reading!</div>
<div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div>
</div>
<div class=""><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div>
<div class=""><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class=""><br class=""></div>
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></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=""></div></body></html>