-
Notifications
You must be signed in to change notification settings - Fork 248
Add support for InlineArray type sugar #1043
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
Open
TTOzzi
wants to merge
1
commit into
swiftlang:main
Choose a base branch
from
TTOzzi:inline-array-type-sugar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm, the last two of these look incorrect. I would expect the following:
The first two are still a little weird, but is similar to how we handle
ArrayTypeSyntax
—that is, we don't handle it at all and just let whatever's inside it determine how it wraps. That means that even outside of inline array sugar, the thing inside the brackets inlet a: [LongThing]
wraps very differently fromlet a = [LongThing]()
. Let's ignore that for now.The last one is sort of tricky, but we need that line break before the
]
in that case to satisfy our other rules about how continuation lines force a break if there would be an indented line following it.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.
Array types are parsed as
ArrayTypeSyntax
when used in type declarations, and asArrayExprSyntax
when used with initializers.This causes formatting differences between
let a: [LongThing]
andlet a = [LongThing]()
.On the other hand, InlineArray is always parsed as
InlineArrayTypeSyntax
, regardless of context.So if we want to match the formatting behavior of regular arrays, we may need to make
InlineArrayTypeSyntax
explicitly check whether itsparent
conforms toCallingExprSyntaxProtocol
.What do you think about having a consistent line-breaking behavior for inline arrays—regardless of where they’re used—like in the latest commit?
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.
Yeah, I suppose that's a reasonable default for now. It's not optimal, but it'll at least always be "correct" (in terms of following our line wrapping rules), and the chances of someone having this kind of situation aren't that high. We can revisit it later with some of the other types of nodes. Thanks!
Uh oh!
There was an error while loading. Please reload this page.
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 line breaks may seem excessive because thelinelength
limit is set to an extremely low value (5),but with a more reasonable setting (like 40), the output looks like this:
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.
Hmm, it looks like that with the latest commit? I wouldn't expect that—the
.open
/.close
groups you added inside the brackets should always force3 of
onto the next line if any part of that group breaks, and it should also force the closing bracket to wrap down.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.
Ah, my apologies — I ran the tests after accidentally rolling back the commit.
It's working as expected now. Sorry for the confusion 🙇