<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="">I think that there should be a warning for unused literals. I can't think of any case where you would like to have a literal just hanging there in Swift.<br class=""><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Félix</span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 1 févr. 2016 à 06:15:32, Jens Persson via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_signature"><div class="gmail_signature">func perhapsConfusing() {</div><div class="gmail_signature"> let s =</div><div class="gmail_signature"> "Since this function compiles fine. One might "</div><div class="gmail_signature"> "think that string literals in Swift can be "</div><div class="gmail_signature"> "written like this. But that is not the case. "</div><div class="gmail_signature"> "Only the first string literal will be printed."</div><div class="gmail_signature"> "The rest (including eg this) will be silently "</div><div class="gmail_signature"> "ignored."</div><div class="gmail_signature"> 12.34 // As will this.</div><div class="gmail_signature"> 12 + 4 // And this.</div><div class="gmail_signature"> 123 == 456 // And this.</div><div class="gmail_signature"> print(s) // Prints: "Since this function compiles fine. One might "</div><div class="gmail_signature">}</div><div class="gmail_signature"><br class=""></div><div class="">Besides being possibly surprising for newcomers (who may assume string literals split across several lines as above will be joined), there are some related inconsistencies in whether warnings are generated for unused results or not, for example</div><div class="">123 == 456 // Unused result is silently ignored, while</div><div class="">1.2 == 3.4 // produces a warning: Result of call to '==' is unused.</div><div class="">(The following bug report is about unused results, but it doesn't mention the IMHO similar unused-literals-case: <a href="https://bugs.swift.org/browse/SR-245" class="">https://bugs.swift.org/browse/SR-245</a> )</div><div class=""><br class=""></div><div class="">So my question is:</div><div class="">Should/could there be a warning for unused literals?</div><div class=""><br class=""></div><div class="">/Jens</div><div class=""><br class=""></div></div>
</div>
_______________________________________________<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></blockquote></div><br class=""></body></html>