<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 Mar 24, 2017, at 3:57 PM, Peter Dillinger 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="">I recently criticized Swift 3 for allowing many expressions with no side effects as statements, in this blog post: <a href="https://blogs.synopsys.com/software-integrity/2017/03/24/swift-programming-language-design-part-2/" class="">https://blogs.synopsys.com/software-integrity/2017/03/24/swift-programming-language-design-part-2/</a> (search for "that expression"). &nbsp;I've seen some related discussion such as "Make non-void functions @warn_unused_result by default", but not quite this.<br class=""><br class="">For emphasis, let me include a real example (from open-source software, simplified) of defective JavaScript code that happens to be legal Swift as well:<br class=""><br class="">var html = "&lt;table class='modification'&gt;" +<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&lt;tbody&gt;" +<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trs<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&lt;/tbody&gt;" +<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&lt;/table&gt;";<br class=""><br class="">DEFECT SPOILER: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(There is a missing '+')<br class=""><br class="">Part of my argument is that people commonly ignore compiler warnings. &nbsp;We see lots of defective code that would be (or is) caught by compiler warnings but people don't pay attention.<br class=""><br class="">I have not formulated this into a detailed proposal, but I suspect that because of Swift's pervasive overloading, implicit constructor calls, etc., it would involve introducing a new @error_unused_result annotation and using that in many places in the standard library. &nbsp;I also suggest that user overloads of traditionally non-side-effecting operators, as well as non-mutating struct methods, be @error_unused_result by default, or perhaps by mandate. &nbsp;Our experience also suggests this @error_unused_result feature could also be useful for ordinary methods of classes, as we find a number of defects where a method call is expecting a side effect but there is none, because the method is only useful for its return value.<br class=""><br class="">If you would like to see more defect examples from open-source software (other languages for the moment), I should be able to dig up some more.<br class=""></div></div></blockquote></div><div class=""><br class=""></div><div class="">If I copy/paste your code (and add a definition for “trs”), Swift already gives a warning:</div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> trs = </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"trs"</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> html = </span><span style="font-variant-ligatures: no-common-ligatures" class="">"&lt;table class='modification'&gt;"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">+</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">"&lt;tbody&gt;"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">+</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">trs</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"&lt;/tbody&gt;"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">+</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">// Warning: Result of operator '+' is unused</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">"&lt;/table&gt;"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">;</span></div></div></blockquote><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">What version of Swift are you using? IIRC, it didn’t start doing that until Swift 3.</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">- Dave Sweeris</span></div></body></html>