Skip to content

Commit

Permalink
chore: Formatter can now handle cast expressions (#3000)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom French <tom@tomfren.ch>
  • Loading branch information
kevaundray and TomAFrench authored Oct 9, 2023
1 parent f5a0022 commit 89a0880
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
"{} {} {}",
Expand Down
3 changes: 3 additions & 0 deletions tooling/nargo_fmt/tests/expected/cast.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
x as u8
}
4 changes: 4 additions & 0 deletions tooling/nargo_fmt/tests/input/cast.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {

x as u8
}

0 comments on commit 89a0880

Please sign in to comment.