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

Stephen Celis stephen.celis at gmail.com
Wed Mar 2 19:42:08 CST 2016


> On Mar 2, 2016, at 7:54 PM, David Owens II via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Possibly. I'm genuinely interested in the number of APIs like that. Even if we did want that, I would still prefer a non-attribute solution to the problem.
> Swift already allows overloading based on return-type. One of the problems is that it's just not good at picking the one that you'd want.
> func removeLast() { let _ = removeLast() }
> func removeLast() -> Self.Generator.Element { ... }
> foo.removeLast() // ok, no warning as there is void version
> let item = foo.removeLast()

I like this solution and have wanted Swift to be better about disambiguating this in the past.

This reminds me of another place where I'd like to mark arguments as "discardable" or improve the way Swift disambiguates.

I'd also love this related overload to work without error:

    func handler(body: T -> Void)
    func handler(body: () -> Void)
    handler { arg in … } // Error: "Ambiguous use of 'handler'"
    handler { … }

    // or
    func handler(body: @discardable T -> Void)
    handler { … } // no need to specify "_"

Stephen


More information about the swift-evolution mailing list