[swift-evolution] Make non-void functions @warn_unused_result by default

Jens Persson jens at bitcycle.com
Fri Dec 18 03:32:36 CST 2015


>
> strong +1 from me.  @warn_unused_result is almost always the right answer
> in the standard library, and the few cases where it isn’t are very easy to
> notice (when the call has side-effects and the return value is incidental).
>
> -Dave
>

I'm also in favour of this proposal.

Some days ago, in the swift-dev list (
https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000385.html
) I was advised by Chris Lattner to bring a related issue into this
discussion:

It's about the lack of a warning for simple statements that are unused and
thus meaningless (so most probably unintentional). To demonstrate what I
mean, here's a short example that currently compiles without any warnings:

func thisFuncHasNoWarnings(a: Int) {
    a
    "b"
    "c" as Character
    1.0
    [2.0, 3.0]
    ["four", 5, 6.7] as [Any]
    "Is this"; a; "problem?"
}

I think it might be reasonable to expect a warning on every single line of
that function, no?
/Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151218/45497780/attachment.html>


More information about the swift-evolution mailing list