From 89a0880852c9445694a10be02dbafd1f5a0ee5eb Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 9 Oct 2023 19:38:03 +0100 Subject: [PATCH] chore: Formatter can now handle cast expressions (#3000) Co-authored-by: Tom French --- tooling/nargo_fmt/src/visitor/expr.rs | 3 +++ tooling/nargo_fmt/tests/expected/cast.nr | 3 +++ tooling/nargo_fmt/tests/input/cast.nr | 4 ++++ 3 files changed, 10 insertions(+) create mode 100644 tooling/nargo_fmt/tests/expected/cast.nr create mode 100644 tooling/nargo_fmt/tests/input/cast.nr diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index 6ff640e4e51..5209f669ce1 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -27,6 +27,9 @@ impl FmtVisitor<'_> { ExpressionKind::Prefix(prefix) => { format!("{}{}", prefix.operator, self.format_expr(prefix.rhs)) } + ExpressionKind::Cast(cast) => { + format!("{} as {}", self.format_expr(cast.lhs), cast.r#type) + } ExpressionKind::Infix(infix) => { format!( "{} {} {}", diff --git a/tooling/nargo_fmt/tests/expected/cast.nr b/tooling/nargo_fmt/tests/expected/cast.nr new file mode 100644 index 00000000000..63008168f84 --- /dev/null +++ b/tooling/nargo_fmt/tests/expected/cast.nr @@ -0,0 +1,3 @@ +fn main() { + x as u8 +} diff --git a/tooling/nargo_fmt/tests/input/cast.nr b/tooling/nargo_fmt/tests/input/cast.nr new file mode 100644 index 00000000000..dfbb370e2bb --- /dev/null +++ b/tooling/nargo_fmt/tests/input/cast.nr @@ -0,0 +1,4 @@ +fn main() { + +x as u8 +}