mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Merge pull request #3454 from rtfeldman/fix-opaque-formatting
Fix unstable formatting of opaque tag unions
This commit is contained in:
commit
8c5f798f4e
2 changed files with 33 additions and 18 deletions
|
@ -95,8 +95,6 @@ impl<'a> Formattable for TypeDef<'a> {
|
|||
let ann_is_where_clause =
|
||||
matches!(ann.extract_spaces().item, TypeAnnotation::Where(..));
|
||||
|
||||
let ann_has_spaces_before = matches!(&ann.value, TypeAnnotation::SpaceBefore(..));
|
||||
|
||||
// Always put the has-derived clause on a newline if it is itself multiline, or
|
||||
// the annotation has a where-has clause.
|
||||
let derived_multiline = if let Some(derived) = derived {
|
||||
|
@ -107,12 +105,6 @@ impl<'a> Formattable for TypeDef<'a> {
|
|||
|
||||
let make_multiline = ann.is_multiline() || derived_multiline;
|
||||
|
||||
// If the annotation has spaces before, a newline will already be printed.
|
||||
if make_multiline && !ann_has_spaces_before {
|
||||
buf.newline();
|
||||
buf.indent(indent + INDENT);
|
||||
}
|
||||
|
||||
ann.format(buf, indent);
|
||||
|
||||
if let Some(derived) = derived {
|
||||
|
|
|
@ -5019,6 +5019,20 @@ mod test_fmt {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiline_opaque_tag_union() {
|
||||
expr_formats_same(indoc!(
|
||||
r#"
|
||||
A := [
|
||||
B,
|
||||
C,
|
||||
]
|
||||
|
||||
0
|
||||
"#
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_has_clause() {
|
||||
expr_formats_same(indoc!(
|
||||
|
@ -5029,15 +5043,25 @@ mod test_fmt {
|
|||
"#
|
||||
));
|
||||
|
||||
expr_formats_same(indoc!(
|
||||
r#"
|
||||
A :=
|
||||
U8
|
||||
has [Eq, Hash]
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
r#"
|
||||
A :=
|
||||
U8
|
||||
has [Eq, Hash]
|
||||
|
||||
0
|
||||
"#
|
||||
));
|
||||
0
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
r#"
|
||||
A := U8
|
||||
has [Eq, Hash]
|
||||
|
||||
0
|
||||
"#
|
||||
),
|
||||
);
|
||||
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
|
@ -5049,8 +5073,7 @@ mod test_fmt {
|
|||
),
|
||||
indoc!(
|
||||
r#"
|
||||
A :=
|
||||
a | a has Hash
|
||||
A := a | a has Hash
|
||||
has [Eq, Hash]
|
||||
|
||||
0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue