Fix list-pattern formatting

This commit is contained in:
KtorZ 2024-09-07 11:32:18 +02:00
parent 5ec147e6c7
commit b7ea6ea391
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
4 changed files with 43 additions and 6 deletions

View File

@ -9,6 +9,7 @@
### Changed ### Changed
- **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 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
### Removed ### Removed

View File

@ -1878,12 +1878,16 @@ impl<'comments> Formatter<'comments> {
.. ..
} }
| UntypedExpr::Sequence { .. } | UntypedExpr::Sequence { .. }
| UntypedExpr::Assignment { .. } => " {" | UntypedExpr::Assignment { .. } => Document::Str(" {")
.to_doc() .append(break_("", " ").nest(INDENT))
.append(line().append(self.expr(expr, true)).nest(INDENT).group()) .append(
.append(line()) self.expr(expr, true)
.append("}") .nest(INDENT)
.force_break(), .group()
.append(line())
.append("}")
.force_break(),
),
UntypedExpr::Fn { .. } | UntypedExpr::List { .. } => { UntypedExpr::Fn { .. } | UntypedExpr::List { .. } => {
line().append(self.expr(expr, false)).nest(INDENT).group() line().append(self.expr(expr, false)).nest(INDENT).group()

View File

@ -1247,3 +1247,21 @@ fn format_validator_exhaustive_handlers_extra_non_default_fallback() {
"# "#
); );
} }
#[test]
fn list_pattern() {
assert_format!(
r#"
fn foo() {
when xs is {
[_] -> True
[1, 2] -> False
[_, x] -> {
let y = x
y == 42
}
}
}
"#
);
}

View File

@ -0,0 +1,14 @@
---
source: crates/aiken-lang/src/tests/format.rs
description: "Code:\n\nfn foo() {\n when xs is {\n [_] -> True\n [1, 2] -> False\n [_, x] -> {\n let y = x\n y == 42\n }\n }\n}\n"
---
fn foo() {
when xs is {
[_] -> True
[1, 2] -> False
[_, x] -> {
let y = x
y == 42
}
}
}