Fix formatting of unary operators applied to binary operators.

Add crucial parenthesis...
This commit is contained in:
KtorZ 2023-02-09 13:58:11 +01:00
parent 83a86e6dc0
commit 6be2a9ed80
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 9 additions and 2 deletions

View File

@ -1571,8 +1571,15 @@ impl<'comments> Formatter<'comments> {
fn un_op<'a>(&mut self, value: &'a UntypedExpr, op: &'a UnOp) -> Document<'a> { fn un_op<'a>(&mut self, value: &'a UntypedExpr, op: &'a UnOp) -> Document<'a> {
match op { match op {
UnOp::Not => docvec!["!", self.wrap_expr(value)], UnOp::Not => docvec!["!", self.wrap_unary_op(value)],
UnOp::Negate => docvec!["-", self.wrap_expr(value)], UnOp::Negate => docvec!["-", self.wrap_unary_op(value)],
}
}
fn wrap_unary_op<'a>(&mut self, expr: &'a UntypedExpr) -> Document<'a> {
match expr {
UntypedExpr::BinOp { .. } => "(".to_doc().append(self.expr(expr)).append(")"),
_ => self.wrap_expr(expr),
} }
} }
} }