Fix needed parentheses under trace-if-false disappearing when formatting.

This commit is contained in:
KtorZ 2024-09-08 16:21:45 +02:00
parent b6d99142f9
commit 0c0369ad61
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
7 changed files with 84 additions and 1 deletions

View File

@ -11,6 +11,7 @@
- **aiken-lang**: Fix underflow in error message reported by the validator arity. See [#1013](https://github.com/aiken-lang/aiken/issues/1013) @KtorZ
- **aiken-lang**: Fix list-pattern needlessly formatting over multiple lines. @KtorZ
- **aiken-lang**: Fix formatter on long alternative patterns spanning over multiple lines. @KtorZ
- **aiken-lang**: Fix needed parentheses under trace-if-false operator for todo, fail, unop & pipelines; removed when formatting. @KtorZ
### Removed

View File

@ -2028,7 +2028,17 @@ impl<'comments> Formatter<'comments> {
fn wrap_unary_op<'a>(&mut self, expr: &'a UntypedExpr) -> Document<'a> {
match expr {
UntypedExpr::BinOp { .. } => "(".to_doc().append(self.expr(expr, false)).append(")"),
UntypedExpr::Trace {
kind: TraceKind::Error,
..
}
| UntypedExpr::Trace {
kind: TraceKind::Todo,
..
}
| UntypedExpr::PipeLine { .. }
| UntypedExpr::BinOp { .. }
| UntypedExpr::UnOp { .. } => "(".to_doc().append(self.expr(expr, false)).append(")"),
_ => self.wrap_expr(expr),
}
}

View File

@ -1296,3 +1296,47 @@ fn multiline_alternative_patterns() {
"#
);
}
#[test]
fn trace_if_false_pipeline() {
assert_format!(
r#"
fn main(self) {
(self.extra_signatories |> list.has(self.extra_signatories, config.cold_key))?
}
"#
);
}
#[test]
fn trace_if_false_unop() {
assert_format!(
r#"
fn main(self) {
(!True)?
}
"#
);
}
#[test]
fn trace_if_false_todo() {
assert_format!(
r#"
fn main(self) {
(todo @"whatever")?
}
"#
);
}
#[test]
fn trace_if_false_fail() {
assert_format!(
r#"
fn main(self) {
(fail @"whatever")?
}
"#
);
}

View File

@ -0,0 +1,7 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\nfn main(self) {\n (fail @\"whatever\")?\n}\n"
---
fn main(self) {
(fail @"whatever")?
}

View File

@ -0,0 +1,7 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\nfn main(self) {\n (self.extra_signatories |> list.has(self.extra_signatories, config.cold_key))?\n}\n"
---
fn main(self) {
(self.extra_signatories |> list.has(self.extra_signatories, config.cold_key))?
}

View File

@ -0,0 +1,7 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\nfn main(self) {\n (todo @\"whatever\")?\n}\n"
---
fn main(self) {
(todo @"whatever")?
}

View File

@ -0,0 +1,7 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\nfn main(self) {\n (!True)?\n}\n"
---
fn main(self) {
(!True)?
}