Skip to content

Commit b7ace68

Browse files
authored
fix: format global attributes (#7401)
1 parent b2b632b commit b7ace68

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

test_programs/compile_success_contract/abi_attribute/src/main.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ contract Foo {
44

55
#[abi(bar)]
66
pub struct Bar {
7-
inner: Field
7+
inner: Field,
88
}
99
}

test_programs/compile_success_contract/contract_with_impl/src/main.nr

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
contract Foo {
2-
pub struct T { x: [Field] }
2+
pub struct T {
3+
x: [Field],
4+
}
35

46
impl T {
57
fn t(self) {

test_programs/compile_success_contract/non_entry_point_method/src/main.nr

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
contract Foo {
2-
pub struct PlaceholderStruct{x : u32 }
2+
pub struct PlaceholderStruct {
3+
x: u32,
4+
}
35

46
#[contract_library_method]
57
pub fn has_mut(_context: &mut PlaceholderStruct) {}

test_programs/format.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ echo "[workspace]" > Nargo.toml
3333
echo "members = [" >> Nargo.toml
3434

3535
collect_dirs compile_success_empty
36-
# collect_dirs compile_success_contract
36+
collect_dirs compile_success_contract
3737
collect_dirs compile_success_no_bug
3838
collect_dirs compile_success_with_bug
3939
collect_dirs execution_success

tooling/nargo_fmt/src/formatter/global.rs

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ impl<'a> Formatter<'a> {
1212
let_statement: LetStatement,
1313
visibility: ItemVisibility,
1414
) {
15+
self.format_secondary_attributes(let_statement.attributes.clone());
16+
1517
let group = self.chunk_formatter().format_global(let_statement, visibility);
1618
self.write_indentation();
1719
self.format_chunk_group(group);
@@ -99,4 +101,13 @@ mod tests {
99101
let expected = "pub comptime mut global x: Field = 1;\n";
100102
assert_format(src, expected);
101103
}
104+
105+
#[test]
106+
fn format_global_with_attributes() {
107+
let src = " #[abi ( foo ) ] global x = 1 ; ";
108+
let expected = "#[abi(foo)]
109+
global x = 1;
110+
";
111+
assert_format(src, expected);
112+
}
102113
}

0 commit comments

Comments
 (0)