[swift-users] Compiler can't infer map transfer closure return type?

Jordan Rose jordan_rose at apple.com
Tue Mar 8 19:24:01 CST 2016


> On Mar 7, 2016, at 17:37, Erica Sadun <erica at ericasadun.com> wrote:
> 
> 
>> On Mar 7, 2016, at 6:24 PM, Jordan Rose <jordan_rose at apple.com <mailto:jordan_rose at apple.com>> wrote:
>> 
>> 
>>> On Mar 7, 2016, at 17:21, Erica Sadun <erica at ericasadun.com <mailto:erica at ericasadun.com>> wrote:
>>> 
>>> 
>>>> On Mar 7, 2016, at 6:15 PM, Jordan Rose via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>>>>  Today there's at least a simple rule: if the closure consists of a single expression (or a single return statement), the compiler will look at the body; otherwise it won't.
>>> 
>>> Would it be so hard to have a rule that if there's an unambiguous expression as the last line of a closure that
>>> it automagically acts as a default warn-on-unused-result return? So many of my two-line closures would
>>> benefit from this.
>> 
>> What does that mean? You can't see how the closure is being called, so how do you know if the result is used or unused?
>> 
>> Jordan
>> 
> 
> Okay, fine.
> 
> Would it be so hard to have a rule when there's an unambiguous expression as the last line of a closure that
> it automagically acts as a default return? So many of my two-line closures would benefit from this.

Ah, I see what you mean now. I still think it's a bad idea, though—once you're in "statement mode", flow control ought to be explicit. Other languages have definitely had problems with fall-off-the-end returns <http://programmaticallyspeaking.com/why-i-hate-implicit-return-in-coffeescript.html> when it's not something people use or expect all the time.

Per my (old) discussion on the thread Javier just brought back, @warn_unused_result ought to be catching these for you, and if not then (IMHO) that's the place to be fixing things.

Jordan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160308/c1a81833/attachment.html>


More information about the swift-users mailing list