From dbbbacc32a20d5fe78b83abdefee6f9bc4870e50 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 8 Jul 2022 14:31:31 -0400 Subject: [PATCH] Fix comment between multiline annotation args --- crates/compiler/fmt/src/annotation.rs | 8 +++++--- crates/compiler/fmt/tests/test_fmt.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/compiler/fmt/src/annotation.rs b/crates/compiler/fmt/src/annotation.rs index ef4e6a26bb..4792071aac 100644 --- a/crates/compiler/fmt/src/annotation.rs +++ b/crates/compiler/fmt/src/annotation.rs @@ -207,9 +207,11 @@ impl<'a> Formattable for TypeAnnotation<'a> { match self { Function(arguments, result) => { - let write_parens = parens != Parens::NotNeeded; + let needs_parens = parens != Parens::NotNeeded; - if write_parens { + buf.indent(indent); + + if needs_parens { buf.push('(') } @@ -256,7 +258,7 @@ impl<'a> Formattable for TypeAnnotation<'a> { indent, ); - if write_parens { + if needs_parens { buf.push(')') } } diff --git a/crates/compiler/fmt/tests/test_fmt.rs b/crates/compiler/fmt/tests/test_fmt.rs index 9d89ef8872..f67a513469 100644 --- a/crates/compiler/fmt/tests/test_fmt.rs +++ b/crates/compiler/fmt/tests/test_fmt.rs @@ -4276,6 +4276,21 @@ mod test_fmt { )); } + #[test] + fn comment_between_multiline_ann_args() { + expr_formats_same(indoc!( + r#" + blah : + Str, + # comment + (Str -> Str) + -> Str + + 42 + "# + )) + } + #[test] fn pipeline_apply_lambda_multiline() { expr_formats_same(indoc!(