diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index 5ed6c4bd3df..6c56d96e7a6 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -87,7 +87,9 @@ impl FmtVisitor<'_> { format_parens(self.fork(), exprs.len() == 1, exprs, span) } ExpressionKind::Literal(literal) => match literal { - Literal::Integer(_) => slice!(self, span.start(), span.end()).to_string(), + Literal::Integer(_) | Literal::Bool(_) | Literal::Str(_) | Literal::FmtStr(_) => { + slice!(self, span.start(), span.end()).to_string() + } Literal::Array(ArrayLiteral::Repeated { repeated_element, length }) => { format!("[{}; {length}]", self.format_expr(*repeated_element)) } @@ -97,10 +99,7 @@ impl FmtVisitor<'_> { exprs.into_iter().map(|expr| self.format_expr(expr)).collect(); format!("[{}]", contents.join(", ")) } - - Literal::Bool(_) | Literal::Str(_) | Literal::FmtStr(_) | Literal::Unit => { - literal.to_string() - } + Literal::Unit => "()".to_string(), }, ExpressionKind::Parenthesized(mut sub_expr) => { let remove_nested_parens = self.config.remove_nested_parens; diff --git a/tooling/nargo_fmt/tests/expected/literals.nr b/tooling/nargo_fmt/tests/expected/literals.nr index 44a74a5db68..4dc47bf7e2e 100644 --- a/tooling/nargo_fmt/tests/expected/literals.nr +++ b/tooling/nargo_fmt/tests/expected/literals.nr @@ -9,5 +9,13 @@ fn main() { "hello world"; + "hell\0\"world"; + + f"i: {i}, j: {j}"; + + (); + + (/*test*/); + () } diff --git a/tooling/nargo_fmt/tests/input/literals.nr b/tooling/nargo_fmt/tests/input/literals.nr index 5ca6af41a13..ec7659ac66f 100644 --- a/tooling/nargo_fmt/tests/input/literals.nr +++ b/tooling/nargo_fmt/tests/input/literals.nr @@ -11,5 +11,13 @@ fn main() { "hello world"; + "hell\0\"world"; + + f"i: {i}, j: {j}"; + + ( ); + + (/*test*/); + () }