Skip to content

Commit

Permalink
chore: add member access formatter (noir-lang#3109)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonybur authored Oct 11, 2023
1 parent 12daad1 commit cf42de8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ impl FmtVisitor<'_> {
self.format_expr(infix.rhs)
)
}
ExpressionKind::MemberAccess(member_access_expr) => {
let lhs_str = self.format_expr(member_access_expr.lhs);
format!("{}.{}", lhs_str, member_access_expr.rhs)
}
ExpressionKind::Index(index_expr) => {
let formatted_collection =
self.format_expr(index_expr.collection).trim_end().to_string();
Expand Down
15 changes: 15 additions & 0 deletions tooling/nargo_fmt/tests/expected/member_access.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
struct Address {
city: String,
country: String,
}

struct Person {
name: String,
age: u8,
address: Address,
}

fn foo(p: Person) {
p.name;
p.address.country;
}
15 changes: 15 additions & 0 deletions tooling/nargo_fmt/tests/input/member_access.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
struct Address {
city: String,
country: String,
}

struct Person {
name: String,
age: u8,
address: Address,
}

fn foo(p: Person) {
p . name;
p.address . country;
}

0 comments on commit cf42de8

Please sign in to comment.