From 5e7e342316b03656f9b8ee0e15fe9bf870942b37 Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Fri, 9 Feb 2024 15:35:07 -0500 Subject: [PATCH 1/2] fix: message formatting for assert statement --- tooling/nargo_fmt/src/visitor/stmt.rs | 5 ++++- tooling/nargo_fmt/tests/expected/assert.nr | 1 + tooling/nargo_fmt/tests/input/assert.nr | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tooling/nargo_fmt/src/visitor/stmt.rs b/tooling/nargo_fmt/src/visitor/stmt.rs index b414e5ec5c3..44c5dad6b5d 100644 --- a/tooling/nargo_fmt/src/visitor/stmt.rs +++ b/tooling/nargo_fmt/src/visitor/stmt.rs @@ -38,7 +38,10 @@ impl super::FmtVisitor<'_> { nested_shape.indent.block_indent(self.config); - let message = message.map_or(String::new(), |message| format!(", {message}")); + let message = message.map_or(String::new(), |message| { + let message = rewrite::sub_expr(self, nested_shape, message); + format!(", {message}") + }); let (callee, args) = match kind { ConstrainKind::Assert | ConstrainKind::Constrain => { diff --git a/tooling/nargo_fmt/tests/expected/assert.nr b/tooling/nargo_fmt/tests/expected/assert.nr index 1f38e56b799..7b7fdc13c33 100644 --- a/tooling/nargo_fmt/tests/expected/assert.nr +++ b/tooling/nargo_fmt/tests/expected/assert.nr @@ -1,4 +1,5 @@ fn main(x: Field) { assert(x == 0, "with a message"); assert_eq(x, 1); + assert_eq(x, message); } diff --git a/tooling/nargo_fmt/tests/input/assert.nr b/tooling/nargo_fmt/tests/input/assert.nr index f41e396c041..6cf8c5c4d65 100644 --- a/tooling/nargo_fmt/tests/input/assert.nr +++ b/tooling/nargo_fmt/tests/input/assert.nr @@ -4,4 +4,5 @@ fn main(x: Field) { x, 1 ); + assert_eq( x, message ); } From 74eaea3ce5bedc95eebfaf9bdb2dda45e86b9d8d Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Fri, 9 Feb 2024 15:53:37 -0500 Subject: [PATCH 2/2] chore: fix test --- tooling/nargo_fmt/tests/expected/assert.nr | 2 +- tooling/nargo_fmt/tests/input/assert.nr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tooling/nargo_fmt/tests/expected/assert.nr b/tooling/nargo_fmt/tests/expected/assert.nr index 7b7fdc13c33..805e069c9a7 100644 --- a/tooling/nargo_fmt/tests/expected/assert.nr +++ b/tooling/nargo_fmt/tests/expected/assert.nr @@ -1,5 +1,5 @@ fn main(x: Field) { assert(x == 0, "with a message"); assert_eq(x, 1); - assert_eq(x, message); + assert(x, message); } diff --git a/tooling/nargo_fmt/tests/input/assert.nr b/tooling/nargo_fmt/tests/input/assert.nr index 6cf8c5c4d65..d0259da0e24 100644 --- a/tooling/nargo_fmt/tests/input/assert.nr +++ b/tooling/nargo_fmt/tests/input/assert.nr @@ -4,5 +4,5 @@ fn main(x: Field) { x, 1 ); - assert_eq( x, message ); + assert( x, message ); }