While trailing closures are a common pattern, the lack of required semi-colons in Swift do, I think, lead many programmers to lazily equate a newline with a semicolon, which is not precisely correct.
Adding an explicit notation in order to execute code on newlines after a `return` would be a small price to pay for clarity in a language that does not require semi-colons. (as suggest by author of linked blogpost)
If a programmer puts a return statement in a Void-returning function, I think that's a pretty clear signal that they wish the control flow to end at that point. Maybe I'm missing something related to trailing closures but I don't see how there's a use case for evaluating a Void expression as an argument to `return`, instead of forcing the programmer to have an empty return statement after the expression.
Put another way: Swift has been very good at conditioning programmers to assume that a newline will end the statement except when there's a clear syntactic reason why it shouldn't, and the idea that Swift will view `return \n` in a Void-returning function as an incomplete statement (that should consume the subsequent expression) is non-obvious and unintuitive.
Well I just wasted a good half-hour trying to debug why code was running when I was damn near sure it wasn't supposed to be!( In my case, I was testing a didSet observer and wanted to bail out at a particular point, so rather than highlighting, then commenting out everything, I just tossed in a 'return' statement, then started getting unexpected results since the next line after the return was still being executed. Talk about confusing)!!( I've been a Swift dev for years now and have never come across this completely unintuitive behavior)
It wasn't until I changed the indentation that a warning popped up telling me what the real issue was. Had I not touched the indentation, I wouldn't have seen it, and would still be scratching my head.
To me this is definitely a bug!( There should be no closure after a return. If there is, come up with explicit syntax) Swift is supposed to be really great at being clear, and this time, even to a very experienced dev, left me falling flat on my face and I only got to the bottom of it by accident. Very un-Swifty if you will. (Honestly, I'd say this is a critical bug, but considering as I said, it's the first time I've ever seen this, it would be weird. Then again, it only takes one car crash, right?!
I just spend half a hour trying to find a bug in my code, because closure, which written below return handler in running.
The main problem, that Xcode showed a warning message: "Expression following 'return' is treated as an argument of the 'return'", but I'm used to the message being shown in this case "Code after 'return' will never be executed" and I just didn't pay attention to this message.
I don't know if this behavior needs to be changed.