[swift-users] Compiler can't infer map transfer closure return type?
neil.swift at faiman.org
Mon Mar 7 17:08:29 CST 2016
> On Mar 7, 2016, at 4:33 PM, Jordan Rose <jordan_rose at apple.com> wrote:
> Swift very deliberately does not infer types across multiple statements in closure bodies. This is mostly an implementation restriction (our type-checking system can't handle it very well), but it's also a simple rule that explains the implementation restriction, rather than having type inference in closure bodies working some of the time but not all.
OK. I understand the reasoning, and agree that it makes perfect sense. Thanks for the explanation.
That said … I’ll note that Swift already must have logic to infer a single result type from multiple expressions, to wit, the ?: handling logic. In principle, one could collect all the return expressions in a closure and apply the same logic to them. This would have the happy consequence that common trivial cases like “only one return statement” would work as expected.
But I understand that this is an enhancement request rather than a bug to be fixed, and won’t hold my breath. :-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users