Merge pull request #7409 from joshuawarner32/fuzzing-bugs-5

Fix another batch of parsing/formatting bugs found in fuzzing
This commit is contained in:
Luke Boswell 2024-12-28 17:36:03 +11:00 committed by GitHub
commit f7dbf850b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 750 additions and 74 deletions

View file

@ -291,7 +291,7 @@ fn format_expr_only(
let inner_parens = if needs_parens {
Parens::NotNeeded
} else {
Parens::InApply
Parens::InApplyLastArg
};
if !before_all_newlines {
@ -1314,13 +1314,21 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
after: right_lifted.after,
}
}
Expr::UnaryOp(expr, op) => {
let expr_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &expr.value);
Expr::UnaryOp(inner, op) => {
if parens == Parens::InApply && matches!(inner.without_spaces(), Expr::Closure(..)) {
return Spaces {
before: &[],
item: Expr::ParensAround(arena.alloc(*expr)),
after: &[],
};
}
let inner_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &inner.value);
Spaces {
before: &[],
item: Expr::UnaryOp(arena.alloc(Loc::at(expr.region, expr_lifted.item)), *op),
after: expr_lifted.after,
item: Expr::UnaryOp(arena.alloc(Loc::at(inner.region, inner_lifted.item)), *op),
after: inner_lifted.after,
}
}