Skip to content

Commit

Permalink
chore: resolve escaped string formatting issue (#3165)
Browse files Browse the repository at this point in the history
  • Loading branch information
kek kek kek authored Oct 19, 2023
1 parent e0a89c0 commit 8b4760b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions tooling/nargo_fmt/tests/expected/literals.nr
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ fn main() {

"hello world";

"hell\0\"world";

f"i: {i}, j: {j}";

();

(/*test*/);

()
}
8 changes: 8 additions & 0 deletions tooling/nargo_fmt/tests/input/literals.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@ fn main() {

"hello world";

"hell\0\"world";

f"i: {i}, j: {j}";

( );

(/*test*/);

()
}

0 comments on commit 8b4760b

Please sign in to comment.