diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index 291685d319e..433235e0017 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -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(); diff --git a/tooling/nargo_fmt/tests/expected/member_access.nr b/tooling/nargo_fmt/tests/expected/member_access.nr new file mode 100644 index 00000000000..2330ec826c7 --- /dev/null +++ b/tooling/nargo_fmt/tests/expected/member_access.nr @@ -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; +} diff --git a/tooling/nargo_fmt/tests/input/member_access.nr b/tooling/nargo_fmt/tests/input/member_access.nr new file mode 100644 index 00000000000..abcab671836 --- /dev/null +++ b/tooling/nargo_fmt/tests/input/member_access.nr @@ -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; +}