<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="">Amendment to the history of the bug after I had a look at the bug reports again:&nbsp;<a href="https://bugs.swift.org/browse/SR-1895" class="">SR-1895</a>&nbsp;explicitly asked that&nbsp;<div class=""><br class=""><div class=""><div class="">let s: String? = "hi"</div><div class="">s.map {print($0)}</div><div class=""><br class=""></div><div class="">should not produce any warnings while it did so during beta 1.&nbsp;</div><div class=""><br class=""></div><div class="">– Alex</div></div></div><div class=""><br class=""></div><div style=""><blockquote type="cite" class=""><div class="">On 31 Jan 2017, at 09:07, Alex Hoppen 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=""><div class="">This was a deliberate change between Swift 3 beta 1 and beta 2 after a friend of mine pointed the following inconsistency out to me:<br class=""><br class="">struct Foo {<br class=""> &nbsp;func bar() {}<br class="">}<br class="">let foo: Foo? = Foo()<br class="">foo?.bar() // Does not create a warning<br class="">true ? foo?.bar() : foo?.bar() &nbsp;// expression of type '()?' is unused<br class=""><br class="">After some offline discussion at WWDC with the Swift team we decided to move to a consistent model where ()?, ()??, … is always discardable since we didn't want to take the convenience of foo?.bar() away (something that regularly occurs with weak variables, e.g. captures in closures).<br class=""><br class="">So much for the history of this feature.<br class=""><br class="">– Alex<br class=""><br class=""><br class=""><blockquote type="cite" class="">On 30 Jan 2017, at 22:58, Daniel Duan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">Hi all,<br class=""><br class="">Right now, expressions that evaluates to Optional&lt;()&gt;, Optional&lt;Optional&lt;()&gt;&gt;… gets special treatment when it’s unused. For example:<br class=""><br class="">func f(s: String) {}<br class="">let s: String = “”<br class="">s.map(f) // no warning here, even tho the resulting type is `Optional&lt;()&gt;` and unused.<br class=""><br class="">func g() throws {}<br class="">try? g() // no warnings here neither.<br class=""><br class="">This is convenient, but encourages composing map/filter/reduce, etc with side-effect-ful functions, which we have found a few cases of in our production code recently. Granted, these cases could’ve been caught with more careful code reviews. But we wouldn’t have missed them if this “feature” didn’t exist.<br class=""><br class="">I think we should remove the special treatment so that code in the example above would generate a warning about `()?` being unused. Users can silence it manually by assigning the result to `_`. <br class=""><br class="">OTOH, this would undermine the convenience of `try?` when the throwing function don’t return anything.<br class=""><br class="">What do y’all think?<br class=""><br class="">Daniel Duan<br class="">_______________________________________________<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=""></blockquote><br class="">_______________________________________________<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></div></blockquote></div><br class=""></body></html>