<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 26, 2016, at 6:58 PM, Daniel Duan <<a href="mailto:daniel@duan.org" class="">daniel@duan.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class="">Wouldn't this work in Swift 3 though?</div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">func testFunc(times: Int, fn: (@noescape (Int)->Void)? = nil) { … }</span></div></div></div></blockquote><div><br class=""></div><div>Yes, that got implemented in Swift 3, with a narrow Optional-specific hack :-)</div><div><br class=""></div><div>-Chris</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><br class="">Sent from my iPad</div><div class=""><br class="">On Apr 26, 2016, at 11:26 AM, Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Apr 26, 2016, at 12:15 AM, Aleksandar Petrovic 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=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;" class="">Hi Swift community, I have a question.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;" class="">This is a valid Swift code:</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class="">func testFunc(times: Int, fn: ((Int)->Void)? = nil) {</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>guard let f = fn else { return }</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>for i in 1 ..< times {</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>f(i)</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div id="bloop_customfont" style="margin: 0px;" class="">}</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">And this is not:</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class="">func testFunc(times: Int, @noescape fn: ((Int)->Void)? = nil) {</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>guard let f = fn else { return }</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>for i in 1 ..< times {</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>f(i)</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div id="bloop_customfont" style="margin: 0px;" class="">}</div><div class=""><br class=""></div><div class="">I can't think of any hard reason why the @noescape parameter of the function can't be nullable (and, with default value, be optional), but maybe I'm missing something. Is there any plan to correct this in 3.0?</div></div></div></div></blockquote><br class=""></div><div class="">There are two ways to fix this: a horrible hack that special cases optionals, or the more principled solution that treats optional as the underlying enum type that it is, and making @noescape propagate through to the members of the .some case.</div><div class=""><br class=""></div><div class="">You can probably guess this, but I’d prefer to discuss fixing the full generality of the problem, not providing a special case in the compiler for this.</div><div class=""><br class=""></div><div class="">-Chris</div><br class=""></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></div></blockquote></div><br class=""></body></html>