[swift-evolution] Make non-void functions @warn_unused_result by default
Haravikk
swift-evolution at haravikk.me
Thu Feb 25 01:50:18 CST 2016
> On 25 Feb 2016, at 05:19, Paul Ossenbruggen via swift-evolution <swift-evolution at swift.org> wrote:
>
> These lack conciseness. What about the already supported:
>
> let _ = ingoreResult()
This could work until we gain some other, general purpose, method to suppress warnings, though it isn’t pretty IMO. For example, if a class’ methods are designed to be chain able then the result isn’t necessary (it’s just self), so in things like loops you could end up having to use let _ an awful lot, like so:
class Chainable {
var value = 0
func add(add:Int) {
value += add
return self
}
}
let chainable = Chainable()
for _ in 0 ..< 10 {
if getSomeCondition() {
let _ = chainable.add(5)
} else {
let _ = chainable.add(2)
}
}
Stupid example, but imagine if there were a few other operations, perhaps handled by other conditionals, then suddenly you end up with a lot of these let _ statements, which is why being able to suppress the warnings in all cases is still desirable.
On the topic of verbosity in the attribute, I don’t think there’s any need to go to four words; the current attribute is @warn_unused_result, and I think that @ignore_unused_result works a direct opposite (i.e- the result being unused is still strange to the compiler, but it chooses not to issue a warning about it). I’m only using snake case because that’s what the current value has, obviously we’ll adjust for whatever the final attribute naming convention turns out to be.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160225/4b248389/attachment.html>
More information about the swift-evolution
mailing list