[swift-evolution] Warning on the '(T...) -> U' to '(T...) -> ()' conversion

Erica Sadun erica at ericasadun.com
Mon Feb 8 21:47:03 CST 2016


> On Feb 8, 2016, at 8:32 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Feb 8, 2016, at 7:25 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Javier Soto brought up a case where his ReactiveCocoa code silently did the wrong thing by implicitly discarding the result of a closure:
>> 
>> https://twitter.com/Javi/status/695680700033306624
>> 
>> Since it sounds like we plan on making `@warn_unused_result` the default, it seems natural to also warn when a closure has its result type converted away to Void. If there's one 'return' statement, we could dive into the return expression to decide whether to warn based on the function whose result is getting ignored.
> 
> There's another axis of intent in whether the closure was written with an explicit return or not. `{ foo($0) }` is ambivalent to whether it intends to propagate the value returned by `foo` or not, whereas `{ return foo($0) }` is explicitly trying to do so. IMO we have a stronger case to warn if the `return` is explicit in the closure body.


if foo  is -> Void, it's a gimme.
if foo is -> T with @warn_unused_result, it's a gimme
if foo is -> T without @warn_unused_result, dunno

-- E



More information about the swift-evolution mailing list