<div dir="ltr">A pull request to the standard library would be appreciated.<div><br></div><div>Dmitri<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 12, 2016 at 1:01 PM, Andrew Bennett via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm +1 on <span style="font-size:13px">@warn_unused_result, does that need a proposal or is a PR sufficient?</span></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Jan 12, 2016 at 7:45 AM, Joe Groff via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div style="word-wrap:break-word"><span><br><div><blockquote type="cite"><div>On Jan 11, 2016, at 12:39 PM, Jared Sinclair via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px">Consider the following:</div><div style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px"><div style="margin:0px"><font face="Courier" color="#9437ff">protocol Updatable {</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> func update(state: Bool)</font></div><div style="margin:0px"><font face="Courier" color="#9437ff">}</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"><br></font></div><div style="margin:0px"><font face="Courier" color="#9437ff">class Thing: Updatable {</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> private var enabled = false</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> </font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> func update(state: Bool) {</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> self.enabled == state</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> }</font></div><div style="margin:0px"><font face="Courier" color="#9437ff">}</font></div><div style="margin:0px"><br></div><div style="margin:0px">The obvious intention is to set<span> </span><font color="#9437ff" face="Courier">self.enabled</font><span> </span>to the incoming value of<span> </span><font color="#9437ff" face="Courier">state</font>. However, it’s easy to accidentally type a second equals sign. The effect of this typo is <font color="#9437ff" face="Courier">self.enabled</font> is never updated, leading to a run-time bug that could be difficult to diagnose. </div><div style="margin:0px"><br></div><div style="margin:0px">This typo doesn’t generate any errors or warnings. I can’t think of a valid reason to use the equals function outside of comparisons. If the compiler instead treated this typo as an error, the mistake would be trivial to identify and fix:</div></div><div style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0px"><font face="Courier" color="#9437ff">protocol Updatable {</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> func update(state: Bool)</font></div><div style="margin:0px"><font face="Courier" color="#9437ff">}</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"><br></font></div><div style="margin:0px"><font face="Courier" color="#9437ff">class Thing: Updatable {</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> private var enabled = false</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> </font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> func update(state: Bool) {</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> self.enabled == state // Error: `==` may not be used outside of comparisons</font></div><div style="margin:0px"><font face="Courier" color="#9437ff"> }</font></div><div style="margin:0px"><font face="Courier" color="#9437ff">}</font></div></div></div></blockquote><br></div></span><div>If it isn't already, the implementation of `==` ought to be marked with the `@warn_unused_result` attribute, which will give you a warning if the result is ignored. We're discussing making warn_unused_result the default behavior in another thread.</div><div><br></div><div>-Joe</div><br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=pQw7h83fWt3LLbgkfL4TSUL0weaZnVFZxDe5GShw4uTPUNX5LE7jlGGN0y-2FR9uWwM2b25CU2dU2RBKnYAFVo3GJ33KcCUpBRwqV0Rx05iN-2BE8g7ACc-2FG6H-2BrYpIZuFpm6bhMTZX1inQMz2PJuDO-2BW7lVTHl921yRUaCbu10eXArNm9A9fHCRLGydVzxNtv5rBDr7v2x9OYGRjGrLrdLnJPSXuHDG8RJ9VPpCo64SaqI-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br></div></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=HvbB2rNqe6WERAH1f5iSygoap13wP4MPscYBJZE6r40Xum6RdD-2BDzcxPXBa71RA021e3VZ9MkSsXoELkNLE9aizZEAw9wDIMC20tigrjRMLx1x7Vh1mcSmQ8w8boFK2hEdsM6kQeAxQAmlKWLxudjBloOMj38GzlhzVLskllGutJ0sAO60qNSb6oWMKmzpz-2B8ildlyU2ppH7-2Fjka49qf2GtzY-2BJZ8TVWq-2Bc3bz4Fdto-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>>*/</div>
</div></div></div>