-
Notifications
You must be signed in to change notification settings - Fork 441
Improvements for do
and related statements
#511
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
Conversation
@@ -22,7 +22,7 @@ final class StructTests: XCTestCase { | |||
let nestedStruct = StructDecl( | |||
structKeyword: .struct.withLeadingTrivia(.docLineComment("/// A nested struct\n")), | |||
identifier: "NestedStruct", | |||
genericParameterClause: GenericParameterClause { | |||
genericParameterClause: GenericParameterClause(rightAngleBracket: .rightAngle.withoutTrailingTrivia()) { |
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.
This is a temporary fix needed because of updates for the where
keyword. I'm going to remove it with adjusting spaces around angle brackets in my next PR
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.
I’m not sure how big the changes for the angle brackets are but feel free to include them in this PR.
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.
Not big, however I'd like to make a separate PR for them
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.
The spacing changes look good to me. I’m not entirely convinced about CatchItems
.
CatchClause(CatchItems { | ||
CatchItem(pattern: "Error1") | ||
CatchItem(pattern: "Error2") | ||
}) { |
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.
I’m not entirely convinced this is much better than the default implementation that’s already provided.
CatchClause(CatchItems { | |
CatchItem(pattern: "Error1") | |
CatchItem(pattern: "Error2") | |
}) { | |
CatchClause(catchItems: CatchItemList([ | |
CatchItem(pattern: "Error1"), | |
CatchItem(pattern: "Error2") | |
])) { |
Do you have some example where the result builder syntax is superior than using an array here?
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.
- Result builder automatically inserts trailing commas
- This
CatchClause
convenience initializer adds trailing space to thecatch
keyword
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.
- I really don’t like the idea of introducing yet another type for catch items. We now have
CatchItemsListSyntax
,CatchItemsList
andCatchItems
. What do you think about adding an initializer like the following toCatchItemList
. We could add the same for all syntax collections:
public init(@CatchItemListBuilder itemsBuilder: () -> ExpressibleAsCatchItemList) {
self = itemsBuilder().createCatchItemList()
}
- Can’t we just mark the
catch
keyword asrequires_trailing_space
in https://github.com/apple/swift/blob/5dfa894ea773c1cb82106d831cd4d2df4a837b75/utils/gyb_syntax_support/Token.py#L188?
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.
- Great idea, I've raised Element List initializers accepting result builder #519 for it
- I actually did the opposite to avoid double space when there is no catch items, so I'd like to keep this convenience initializer
@@ -22,7 +22,7 @@ final class StructTests: XCTestCase { | |||
let nestedStruct = StructDecl( | |||
structKeyword: .struct.withLeadingTrivia(.docLineComment("/// A nested struct\n")), | |||
identifier: "NestedStruct", | |||
genericParameterClause: GenericParameterClause { | |||
genericParameterClause: GenericParameterClause(rightAngleBracket: .rightAngle.withoutTrailingTrivia()) { |
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.
I’m not sure how big the changes for the angle brackets are but feel free to include them in this PR.
@ahoppen any comments for the updated implementation? |
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.
Sorry that I missed this. LGTM.
@swift-ci Please test |
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
* Leading/trailing spaces are updated to make statements well formatted * `CatchClause` convenience initializer that calculates spacing around the `catch` keyword * Test coverage for above changes
@swift-ci Please test |
CatchClause
convenience initializer that calculates spacing around thecatch
keywordswiftlang/swift#60204