<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br>On Jan 31, 2017, at 8:47 AM, Alex Hoppen <<a href="mailto:alex@ateamer.de">alex@ateamer.de</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8">Amendment to the history of the bug after I had a look at the bug reports again: <a href="https://bugs.swift.org/browse/SR-1895" class="">SR-1895</a> explicitly asked that <div class=""><br class=""><div class=""><div class="">let s: String? = "hi"</div><div class="">s.map {print($0)}</div></div></div></div></blockquote><div><br></div>This is the anti-pattern we try to discourage. FYI.<br><div><br></div><blockquote type="cite"><div><div class=""><div class=""><div class="">should not produce any warnings while it did so during beta 1. </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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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=""> 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() // 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">Hi all,<br class=""><br class="">Right now, expressions that evaluates to Optional<()>, Optional<Optional<()>>… 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<()>` 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></blockquote></div><br class=""></div></blockquote></body></html>