-
Notifications
You must be signed in to change notification settings - Fork 204
Add discussion of 'if' and 'switch' expressions [SE-0380] #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add discussion of 'if' and 'switch' expressions [SE-0380] #111
Conversation
The test cases that exercise this feature include switches over a Bool
with just a true and false case.
swiftlang/swift#63378
This just follows the principle from the rest of Swift that switches
must be exhaustive -- it's not a special case here -- which is probably
why the SE proposal doesn't call it out like it does for 'if'
expressions needing an 'else' clause.
Today if & switch expressions are interesting because they're new -- but over time they'll be less something novel and more just something that works. Introducing them as part of introducing the corresponding statement form, as an alternate spelling, should age better.
Looking at the test cases from compiler PR 63022 and testing out various behavior myself using the 2023-03-02-a development snapshot.
|
I may need to hold off merging this into 'main' if it doesn't land for Swift 5.8. It was cherry-picked from 'main' (swiftlang/swift#63378) but then reverted (swiftlang/swift#63649) because of a build failure (swiftlang/swift#63979). The GitHub issue is tagged for Swift 5.9, so I assume that means we no longer expect this in Swift 5.8. |
|
@hamishknight and @airspeedswift I added you as reviewers on this PR since you're the authors of the SE proposal. There are a few technical questions I've called out in the diff. Please have a look and call out any technical issues you see. After we're sure the content is factually accurate, I'll do separate review pass with DevPubs editorial, so please try not to focus on polishing the prose. |
- Note that conditional expressions can nest. - Clarify conditional expressions behavior inside a result builder. - Fix copy/paste error in the grammar. Co-authored-by: Hamish Knight <hamish_knight@apple.com>
Per suggestion from Hamish Knight <hamish_knight@apple.com>.
hamishknight
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo the question about code styling, thanks!
chuckdude
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edits and a couple queries where a wording fix is needed. Please let me know if you have any questions or would like to discuss.
Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
chuckdude
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving these changes. There are two open questions that I've responded to, but feel those are within reach, so approving this ahead of Alex's fix for those.
Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
279a9ce to
9b37cf1
Compare
Added a brief example of this syntax in the tour.
Added examples of this syntax alongside the existing
ifandswitchstatements in the guide. I opted to explain it inline, rather than adding a new "If/Switch Expressions" section, because I think that will age better. Today, this syntax is salient because it's new, but after a few years it will just be part of the language — and in the latter context, integrating it gives a better learning path.Added a new "Conditional Expressions" section to the reference, which leans heavily on the existing "Conditional Statements" section but calls out the differences in behavior and requirements, and which describes the formal grammar of
conditional-expression.Fixes: rdar://104936324