Skip to content
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

fix: formatter didn't format >>= well #6337

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions tooling/nargo_fmt/src/formatter/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,15 @@ impl<'a, 'b> ChunkFormatter<'a, 'b> {
if formatter.is_at(Token::Assign) {
formatter.write_token(Token::Assign);
} else {
while formatter.token != Token::Assign {
formatter.write_current_token();
formatter.bump();
formatter.skip_comments_and_whitespace();
}
formatter.write_token(Token::Assign);
// This is something like `x += 1`, which is parsed as an
// Assign with an InfixExpression as its right-hand side: `x = x + 1`.
// There will always be two tokens here, like `+ =` or `> >=`.
formatter.write_current_token();
formatter.bump();
formatter.skip_comments_and_whitespace();
formatter.write_current_token();
formatter.bump();

is_op_assign = true;
}
formatter.write_space();
Expand Down Expand Up @@ -435,6 +438,16 @@ mod tests {
assert_format(src, expected);
}

#[test]
fn format_shift_right_assign() {
let src = " fn foo() { x >>= 2 ; } ";
let expected = "fn foo() {
x >>= 2;
}
";
assert_format(src, expected);
}

#[test]
fn format_comptime_let_statement() {
let src = " fn foo() { comptime let x = 1 ; } ";
Expand Down
Loading