[swift-evolution] [Pitch] Make `return` optional in computed properties for a single case
Adrian Zubarev
adrian.zubarev at devandartist.com
Tue May 31 13:45:13 CDT 2016
I feel like return is very important part of guard statement. I understand the requirement for consistency with properties/closures/functions, but I’ll prefer to have some inconsistency in language in this case and require return for guard. And in case I’ll have to choose all-or-nothig, I’ll give –1 for the proposal.
What’s the problem with single-expression guards? guard cannot fall trough and the type is inferred as the same as its parent closure has.
If we’d like to have this consistence everywhere in the language, guards will be part of that as well.
I’d interpret that as being able to write:
var x: Int8 { 20 }
as opposed to:
var x: Int8 { Int8(20) }
Comment:
Integer literals are untyped and pick up the type of their context.
Joe Groff
—
Under “Proposed solution” you say (emphasis mine):
“Make return optional and infer return type for single-expressions everywhere in the language:”
However the return type isn’t inferred for computed properties or functions, and I don’t see type inference being discussed in the proposal (other than mentioning that closures have it).
Is it worth discussing? I was using Brent’s words here, because my English isn’t that great:
This actually doesn’t have anything to do with @autoclosure or @noescape. Any one-expression closure can omit the return statement and have an inferred return type.
I could remove that from the proposal to sort out any confusion. It should be crystal clear that return should be optional for single-expressions.
--
Adrian Zubarev
Sent with Airmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160531/df9781d5/attachment.html>
More information about the swift-evolution
mailing list