<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 11 Oct 2016, at 07:16, Karl wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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;">You might expect this code to work:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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;"><br class=""></div><blockquote class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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 0px 0px 40px; border: none; padding: 0px;"><div class=""><span class="" style="font-family: Courier;">func</span><span class="" style="font-family: Courier;">&nbsp;aFunction() -&gt;&nbsp;</span><span class="" style="font-family: Courier;">Int</span><span class="" style="font-family: Courier;">?&nbsp;</span><span class="" style="font-family: Courier;">&nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Courier;">{&nbsp;</span><span class="" style="font-family: Courier;">return</span><span class="" style="font-family: Courier;">&nbsp;</span><span class="" style="font-family: Courier;">5&nbsp;}</span></div><div class=""><font face="Courier" class="">func&nbsp;bFunction()&nbsp;throws&nbsp;-&gt;&nbsp;Int&nbsp;{&nbsp;return&nbsp;4&nbsp;}</font></div><div class=""><br class=""></div><div class=""><font face="Courier" class="">let&nbsp;value =&nbsp;aFunction() ??&nbsp;try&nbsp;bFunction() // ERROR: Operator can throw but expression is not marked with a ‘try'</font></div><div class=""><font face="Courier" class="">print(value)</font></div></blockquote><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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;">Instead, you must put the ‘try’ before the entire expression:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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;"><br class=""></div><blockquote class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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 0px 0px 40px; border: none; padding: 0px;"><div class=""><font face="Courier" class="">let&nbsp;value = try&nbsp;aFunction() ??&nbsp;bFunction()</font></div></blockquote><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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;">This is awkward, since aFunction() doesn’t throw.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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;">I propose we change the grammar to allow the first example and disallow the second, consistent with the idea that throwing calls are ‘marked’ by using the try keyword.</div></div></blockquote></div><br class=""><div class=""><div class="">The `??` function <b class=""><i class="">rethrows</i></b> an error from its rhs operand.</div><div class=""><br class=""></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>@_transparent</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>public func ?? &lt;T&gt;(optional: T?, defaultValue: @autoclosure () throws -&gt; T)</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;rethrows -&gt; T {</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;switch optional {</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;case .some(let value):</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;return value</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;case .none:</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;return try defaultValue()</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;}</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><br class=""></div><div class="">&lt;<a href="https://github.com/apple/swift/blob/5d3a7f7c230ae238c848a06f58b58c7e68fb5ed0/stdlib/public/core/Optional.swift#L415-L424" class="">https://github.com/apple/swift/blob/5d3a7f7c230ae238c848a06f58b58c7e68fb5ed0/stdlib/public/core/Optional.swift#L415-L424</a>&gt;</div><div class=""><br class=""></div><div class="">-- Ben</div></div><div class=""><br class=""></div></body></html>