<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body 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="color: rgb(0, 0, 0); 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; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>

</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On Jul 13, 2017, at 19:46, iCloud via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; 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 &lt;A, B, C&gt; (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="">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">B</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) -&gt;</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="">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) -&gt; ((</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="">) -&gt; (</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) - &gt; (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 &lt;————&nbsp;<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 &lt;A, B, C&gt; (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="">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">B</span><span style="font-variant-ligatures: no-common-ligatures" class="">)) -&gt; (</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="">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">))) -&gt; ((</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="">) -&gt; (</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="">&nbsp; &nbsp;</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="">&nbsp; &nbsp; &nbsp; &nbsp;</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="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 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="">&nbsp; &nbsp; &nbsp; &nbsp; }</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="">&nbsp; &nbsp; }</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&nbsp;</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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>