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

Paul Ossenbruggen possen at gmail.com
Thu Mar 3 09:41:35 CST 2016

I really like the proposal use of @discardable, i would add to it that the word “let" is optional in the proposal. Because we are not using the result it does not matter that that keyword is there. It follows the pattern already established in for loops. 

for _ in nodes {

No let there. So:

   	_ = discardableResult() 

Makes sense and is much more concise. 

One other question, for pure functions, would it be desirable to have it be an error that the caller never uses the result and that _ = is not an  acceptable thing to do for them? 

- Paul

> On Mar 2, 2016, at 8:16 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
>> On Mar 2, 2016, at 4:13 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.
> I don’t get that.  If X.removeLast() returned a result, but also had an important side effect, I would expect it to be one of the (few but important) cases that would be marked with the @discardable attribute, so it would not produce a warning.
>> 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.
> I can’t imagine any scenario where @discardable would impact resilience.
> -Chris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160303/49457e7e/attachment.html>

More information about the swift-evolution mailing list