From 7ba51356021570da66a7c3831779ca40ec8c6d18 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 18 Dec 2024 10:35:18 -0800 Subject: [PATCH] Fix as in apply type --- crates/compiler/fmt/src/annotation.rs | 4 +- ..._parens_as_parens_h_ann.expr.formatted.roc | 2 + .../h_parens_as_parens_h_ann.expr.result-ast | 62 +++++++++++++++++++ .../pass/h_parens_as_parens_h_ann.expr.roc | 2 + .../test_syntax/tests/test_snapshots.rs | 1 + 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.formatted.roc create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.result-ast create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.roc diff --git a/crates/compiler/fmt/src/annotation.rs b/crates/compiler/fmt/src/annotation.rs index 3caf8345ee..4dd224cfdf 100644 --- a/crates/compiler/fmt/src/annotation.rs +++ b/crates/compiler/fmt/src/annotation.rs @@ -367,13 +367,13 @@ fn fmt_ty_ann( } TypeAnnotation::As(lhs, spaces, TypeHeader { name, vars }) => { - let write_parens = parens == Parens::InAsPattern; + let write_parens = parens == Parens::InAsPattern || parens == Parens::InApply; + buf.indent(indent); if write_parens { buf.push('(') } - buf.indent(indent); let lhs_indent = buf.cur_line_indent(); lhs.value .format_with_options(buf, Parens::InAsPattern, Newlines::No, indent); diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.formatted.roc b/crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.formatted.roc new file mode 100644 index 0000000000..70ec592b74 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.formatted.roc @@ -0,0 +1,2 @@ +N : A (H as H) H +I \ No newline at end of file diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.result-ast b/crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.result-ast new file mode 100644 index 0000000000..d2577b5a2d --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.result-ast @@ -0,0 +1,62 @@ +@0-16 SpaceAfter( + Defs( + Defs { + tags: [ + EitherIndex(0), + ], + regions: [ + @0-14, + ], + space_before: [ + Slice { start: 0, length: 0 }, + ], + space_after: [ + Slice { start: 0, length: 0 }, + ], + spaces: [], + type_defs: [ + Alias { + header: TypeHeader { + name: @0-1 "N", + vars: [], + }, + ann: @2-14 Apply( + "", + "A", + [ + @5-0 As( + @5-6 Apply( + "", + "H", + [], + ), + [], + TypeHeader { + name: @10-11 "H", + vars: [], + }, + ), + @13-14 Apply( + "", + "H", + [], + ), + ], + ), + }, + ], + value_defs: [], + }, + @15-16 SpaceBefore( + Tag( + "I", + ), + [ + Newline, + ], + ), + ), + [ + Newline, + ], +) diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.roc b/crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.roc new file mode 100644 index 0000000000..e947cd6608 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/h_parens_as_parens_h_ann.expr.roc @@ -0,0 +1,2 @@ +N:A((H)as H) H +I diff --git a/crates/compiler/test_syntax/tests/test_snapshots.rs b/crates/compiler/test_syntax/tests/test_snapshots.rs index 074da1119d..559d10d508 100644 --- a/crates/compiler/test_syntax/tests/test_snapshots.rs +++ b/crates/compiler/test_syntax/tests/test_snapshots.rs @@ -436,6 +436,7 @@ mod test_snapshots { pass/function_with_tuple_ext_type.expr, pass/function_with_tuple_type.expr, pass/h_greater_comment_minus_div.expr, + pass/h_parens_as_parens_h_ann.expr, pass/highest_float.expr, pass/highest_int.expr, pass/i_over_not_g.expr,