Skip to content

Commit 3972ead

Browse files
authored
fix: message formatting for assert statement (#4323)
# Description Due to our use of Display for message formatting, we were generating invalid code. Output before the PR: ```rust assert(x, plain::message); ``` Output after the PR: ```rust assert(x, message); ``` ## Documentation Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
1 parent 69b8912 commit 3972ead

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

tooling/nargo_fmt/src/visitor/stmt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ impl super::FmtVisitor<'_> {
3838

3939
nested_shape.indent.block_indent(self.config);
4040

41-
let message = message.map_or(String::new(), |message| format!(", {message}"));
41+
let message = message.map_or(String::new(), |message| {
42+
let message = rewrite::sub_expr(self, nested_shape, message);
43+
format!(", {message}")
44+
});
4245

4346
let (callee, args) = match kind {
4447
ConstrainKind::Assert | ConstrainKind::Constrain => {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fn main(x: Field) {
22
assert(x == 0, "with a message");
33
assert_eq(x, 1);
4+
assert(x, message);
45
}

tooling/nargo_fmt/tests/input/assert.nr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ fn main(x: Field) {
44
x,
55
1
66
);
7+
assert( x, message );
78
}

0 commit comments

Comments
 (0)