Fix possible exception with initializer body close to column limit #257
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.
Before this PR
When formatting far-off (close to 120 characters) lambda or assignment body, the formatting code could throw an exception.
This would happen if the body contained an empty level, such as the case when e.g. doing
new SomeClass<>()
: there is an empty level created for the type arguments inside<>
, but it's empty because there are no type arguments.This would throw off the logic that decides whether trying to put such body onto the next line results in it taking only one line (in
handle_breakOnlyIfInnerLevelsThenFitOnOneLine
).It could first infer that the empty level was broken (marked as such because the column would have already exceeded 120 columns), but then later down the line
tryInlinePrefixOntoCurrentLine
would try to find this broken level, only this time it would filter out empty levels, and so never find that level and throw.After this PR
==COMMIT_MSG==
Fix edge case with empty levels causing formattings very close to the column limit to throw.
==COMMIT_MSG==
Possible downsides?