Fix list-pattern formatting
This commit is contained in:
parent
5ec147e6c7
commit
b7ea6ea391
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue