Fix forc-fmt empty if-body + else collapsing onto one line#7628
Open
Dnreikronos wants to merge 3 commits into
Open
Fix forc-fmt empty if-body + else collapsing onto one line#7628Dnreikronos wants to merge 3 commits into
Dnreikronos wants to merge 3 commits into
Conversation
When an if-block has an empty body and an else clause, the formatter
wrote no newline before the closing brace, producing collapsed output
like `if cond { } else if ...` on a single line.
Write a newline after the empty body when an else clause exists, and
skip block_unindent since close_curly_brace in format_else_opt already
handles it. Guard with LineStyle::Inline to avoid injecting newlines
during width measurement probes.
Closes FuelLabs#7625
Add expr-level test for empty if + else-if and integration tests for empty if + else-if and empty if + else with long lines that prevent inlining.
PR SummaryLow Risk Overview Adds regression coverage for this case (including a long-condition Reviewed by Cursor Bugbot for commit ba6e570. Bugbot is set up for automated code reviews on this repo. Configure here. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes #7625
forc-fmtcollapses empty if-body + else onto a single line:Root cause: In
format_then_block, when the then-block is empty and has an else clause,block_unindent()was called but no newline was written — so the closing}fromformat_else_optended up on the same line.Fix: Write a newline after the empty body when an else clause exists, and skip
block_unindentsinceclose_curly_braceinformat_else_optalready handles unindentation. Guarded withLineStyle::Inlineto avoid injecting newlines during width measurement probes.Checklist
Breaking*orNew Featurelabels where relevant.