[swift-evolution] Make non-void functions @warn_unused_result by default
David Owens II
david at owensd.io
Wed Mar 2 18:54:58 CST 2016
On 3/2/2016 4:13:38 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
> My primary preference is to just say that's the way it is. I don't particular like any of the attributes. Also, we have a mechanism to discard the result already:
>
> let _ = discardableResult()
Do you really want to require that for, say, `RangeReplaceableCollectionType.removeLast()`? Because that's what this implies.
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 don't think that's a good idea. It would make the warning more noisy, which would ultimately make it meaningless.
> For resiliency, is adding a `@discardable` attribute a breaking change? Removing it?
If it has any resiliency implications at all, removing it would break. But I don't think it would; it merely controls a warning, and doesn't necessarily imply any change in semantics.
At the very least, it's a source-level breaking change.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160302/ed9edb09/attachment.html>
More information about the swift-evolution
mailing list