Skip to content

Conversation

@amartini51
Copy link
Member

@amartini51 amartini51 commented Mar 8, 2023

Added a brief example of this syntax in the tour.

Added examples of this syntax alongside the existing if and switch statements 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

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.
@amartini51
Copy link
Member Author

amartini51 commented Mar 8, 2023

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.

@amartini51 amartini51 marked this pull request as ready for review March 8, 2023 01:02
@amartini51
Copy link
Member Author

@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.

amartini51 and others added 6 commits March 9, 2023 11:37
- 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>.
Copy link
Contributor

@hamishknight hamishknight left a 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!

@amartini51 amartini51 requested a review from chuckdude April 21, 2023 00:24
Copy link
Contributor

@chuckdude chuckdude left a 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.

amartini51 and others added 2 commits April 26, 2023 13:52
Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
amartini51 and others added 2 commits April 26, 2023 13:54
Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
Copy link
Contributor

@chuckdude chuckdude left a 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>
@amartini51 amartini51 force-pushed the if_expression_104936324 branch from 279a9ce to 9b37cf1 Compare April 28, 2023 20:09
@amartini51 amartini51 merged commit 372c30f into swiftlang:main May 26, 2023
@amartini51 amartini51 deleted the if_expression_104936324 branch May 26, 2023 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants