[swift-evolution] Missing warnings for unused literals (and results)?
Jens Persson
jens at bitcycle.com
Mon Feb 1 05:15:32 CST 2016
func perhapsConfusing() {
let s =
"Since this function compiles fine. One might "
"think that string literals in Swift can be "
"written like this. But that is not the case. "
"Only the first string literal will be printed."
"The rest (including eg this) will be silently "
"ignored."
12.34 // As will this.
12 + 4 // And this.
123 == 456 // And this.
print(s) // Prints: "Since this function compiles fine. One might "
}
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
123 == 456 // Unused result is silently ignored, while
1.2 == 3.4 // produces a warning: Result of call to '==' is unused.
(The following bug report is about unused results, but it doesn't mention
the IMHO similar unused-literals-case: https://bugs.swift.org/browse/SR-245
)
So my question is:
Should/could there be a warning for unused literals?
/Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160201/48131230/attachment.html>
More information about the swift-evolution
mailing list