[swift-evolution] [Review] SE-0047 Defaulting non-Void functions so they warn on unused results

Adrian Kashivskyy adrian.kashivskyy at me.com
Mon Mar 21 18:21:54 CDT 2016


I believe the scoped @discardableResult(warn|critical) attribute is a nice idea for future directions, but I'm not sure it's in scope of this proposal, which, as a first small step, aims to basically invert the @warn_unused_result standard.

cc Erica


Pozdrawiam – Regards,
Adrian Kashivskyy

> Wiadomość napisana przez Haravikk <swift-evolution at haravikk.me> w dniu 21.03.2016, o godz. 22:28:
> 
> 
>> On 21 Mar 2016, at 20:35, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> In Swift Evolution discussions, the term @discardable was mildly preferred over @discardableResult.
>> 
>> Some community members requested a new attribute enabling exceptional imported functions to be properly annotated from Objective-C source.
>> 
>> Dany St-Amant requested two levels of compiler response: @discardableResult(warn) for simple warnings and @discardableResult(critical) which generates an error with unused results, such as when returning allocated resources
>> 
>> 
> 
> This looks good, I think that @discardableResult() makes sense until we can get @discardable on the return type itself. I think that if warn/critical is added then there should also be a corresponding “allow” or similar (which is what the default is), i.e- @discardableResult on its own implies @discardResult(allow) to issue no warnings of any kind.
> 
> I also like the idea of being able to add this attribute to types as well as functions, allowing the default behaviour to be changed on a per-type basis, as this would be useful for types that are specifically designed with method chaining for example (where most results are discardable as standard). While the choice of default will never satisfy everyone, this would make it easy to tweak for your own needs.
> 
> Allow us to do something like the following, assuming that @discardableResult(warn) is now the default:
> 
> 	@discardableResult(allow)
> 	class MyChainableType {
> 		func chainableMethod() -> Self { … }
> 		func anotherChainableMethod() -> Self { … }
> 
> 		@discardableResult(critical)
> 		func getResult() -> Dictionary { … }
> 	}
> 
> Of course, if we can get attributes on return types now or in future, then the function form of the attribute should be @discardable(warn) for .getResult().

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160322/2e1e9907/attachment.html>


More information about the swift-evolution mailing list