diff --git a/crates/compiler/fmt/src/annotation.rs b/crates/compiler/fmt/src/annotation.rs index 9302eac531..52c3147914 100644 --- a/crates/compiler/fmt/src/annotation.rs +++ b/crates/compiler/fmt/src/annotation.rs @@ -365,18 +365,24 @@ fn fmt_ty_ann( buf.push('(') } + buf.indent(indent); + let lhs_indent = buf.cur_line_indent(); lhs.value .format_with_options(buf, Parens::InAsPattern, Newlines::No, indent); buf.spaces(1); format_spaces(buf, spaces, newlines, indent); - buf.indent(indent); + buf.indent(lhs_indent + INDENT); buf.push_str("as"); buf.spaces(1); buf.push_str(name.value); for var in *vars { buf.spaces(1); - var.value - .format_with_options(buf, Parens::NotNeeded, Newlines::No, indent); + var.value.format_with_options( + buf, + Parens::NotNeeded, + Newlines::No, + lhs_indent + INDENT, + ); } if write_parens { diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/annotation_comment_before_as.expr.formatted.roc b/crates/compiler/test_syntax/tests/snapshots/pass/annotation_comment_before_as.expr.formatted.roc new file mode 100644 index 0000000000..fb282309be --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/annotation_comment_before_as.expr.formatted.roc @@ -0,0 +1,3 @@ +e : A # + as H +n \ No newline at end of file diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/annotation_comment_before_as.expr.result-ast b/crates/compiler/test_syntax/tests/snapshots/pass/annotation_comment_before_as.expr.result-ast new file mode 100644 index 0000000000..9712240a0b --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/annotation_comment_before_as.expr.result-ast @@ -0,0 +1,55 @@ +@0-13 SpaceAfter( + Defs( + Defs { + tags: [ + EitherIndex(2147483648), + ], + regions: [ + @0-11, + ], + space_before: [ + Slice { start: 0, length: 0 }, + ], + space_after: [ + Slice { start: 0, length: 0 }, + ], + spaces: [], + type_defs: [], + value_defs: [ + Annotation( + @0-1 Identifier { + ident: "e", + }, + @2-0 As( + @2-3 Apply( + "", + "A", + [], + ), + [ + LineComment( + "", + ), + ], + TypeHeader { + name: @10-11 "H", + vars: [], + }, + ), + ), + ], + }, + @12-13 SpaceBefore( + Var { + module_name: "", + ident: "n", + }, + [ + Newline, + ], + ), + ), + [ + Newline, + ], +) diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/annotation_comment_before_as.expr.roc b/crates/compiler/test_syntax/tests/snapshots/pass/annotation_comment_before_as.expr.roc new file mode 100644 index 0000000000..0da3f929f8 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/annotation_comment_before_as.expr.roc @@ -0,0 +1,3 @@ +e:A# + as H +n diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/parens_newlines_before_as.expr.formatted.roc b/crates/compiler/test_syntax/tests/snapshots/pass/parens_newlines_before_as.expr.formatted.roc index 6dcf1d5363..2831ce277f 100644 --- a/crates/compiler/test_syntax/tests/snapshots/pass/parens_newlines_before_as.expr.formatted.roc +++ b/crates/compiler/test_syntax/tests/snapshots/pass/parens_newlines_before_as.expr.formatted.roc @@ -1,4 +1,4 @@ 1 : * # - as J + as J l \ No newline at end of file diff --git a/crates/compiler/test_syntax/tests/test_snapshots.rs b/crates/compiler/test_syntax/tests/test_snapshots.rs index 0cf0e5b910..1c372e8bfa 100644 --- a/crates/compiler/test_syntax/tests/test_snapshots.rs +++ b/crates/compiler/test_syntax/tests/test_snapshots.rs @@ -298,6 +298,7 @@ mod test_snapshots { pass/annotated_tag_destructure.expr, pass/annotated_tuple_destructure.expr, pass/annotation_apply_newlines.expr, + pass/annotation_comment_before_as.expr, pass/annotation_comment_before_colon.expr, pass/annotation_double_as.expr, pass/annotation_tag_parens_comment.expr,