mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Format spaces in as annotation correctly
This commit is contained in:
parent
24ba9dbeba
commit
9f3f99c573
5 changed files with 73 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
collection::{fmt_collection, Braces},
|
||||
expr::merge_spaces_conservative,
|
||||
expr::{format_spaces, merge_spaces_conservative},
|
||||
node::{Node, Nodify, Sp},
|
||||
pattern::pattern_lift_spaces_after,
|
||||
spaces::{fmt_comments_only, fmt_spaces, NewlineAt, INDENT},
|
||||
|
@ -358,11 +358,12 @@ fn fmt_ty_ann(
|
|||
fmt_ext(ext, buf, indent);
|
||||
}
|
||||
|
||||
TypeAnnotation::As(lhs, _spaces, TypeHeader { name, vars }) => {
|
||||
// TODO use _spaces?
|
||||
TypeAnnotation::As(lhs, spaces, TypeHeader { name, vars }) => {
|
||||
lhs.value
|
||||
.format_with_options(buf, Parens::InFunctionType, Newlines::No, indent);
|
||||
buf.spaces(1);
|
||||
format_spaces(buf, spaces, newlines, indent);
|
||||
buf.indent(indent);
|
||||
buf.push_str("as");
|
||||
buf.spaces(1);
|
||||
buf.push_str(name.value);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
1 :
|
||||
* #
|
||||
as J
|
||||
l
|
|
@ -0,0 +1,54 @@
|
|||
@0-13 SpaceAfter(
|
||||
Defs(
|
||||
Defs {
|
||||
tags: [
|
||||
EitherIndex(2147483648),
|
||||
],
|
||||
regions: [
|
||||
@0-11,
|
||||
],
|
||||
space_before: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
space_after: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
spaces: [],
|
||||
type_defs: [],
|
||||
value_defs: [
|
||||
Annotation(
|
||||
@0-1 NumLiteral(
|
||||
"1",
|
||||
),
|
||||
@3-0 As(
|
||||
@3-4 SpaceAfter(
|
||||
Wildcard,
|
||||
[
|
||||
LineComment(
|
||||
"",
|
||||
),
|
||||
],
|
||||
),
|
||||
[],
|
||||
TypeHeader {
|
||||
name: @10-11 "J",
|
||||
vars: [],
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
},
|
||||
@12-13 SpaceBefore(
|
||||
Var {
|
||||
module_name: "",
|
||||
ident: "l",
|
||||
},
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
1:(*#
|
||||
)as J
|
||||
l
|
|
@ -575,6 +575,7 @@ mod test_snapshots {
|
|||
pass/parens_func_apply_type.expr,
|
||||
pass/parens_in_type_def_apply.expr,
|
||||
pass/parens_newline_in_func_type.expr,
|
||||
pass/parens_newlines_before_as.expr,
|
||||
pass/parens_record_updater.expr,
|
||||
pass/parenthesized_type_def.expr,
|
||||
pass/parenthesized_type_def_space_before.expr,
|
||||
|
@ -744,6 +745,13 @@ mod test_snapshots {
|
|||
true
|
||||
}
|
||||
|
||||
"parens_newlines_before_as" => {
|
||||
// Found unbound type variables {66}
|
||||
// in type alias `Test.IdentId(0)` [] [] : <66>
|
||||
// Location: crates/compiler/can/src/scope.rs:541:13
|
||||
true
|
||||
}
|
||||
|
||||
// When adding new snapshot tests, strongly prefer fixing any canonicalization panics
|
||||
// they may run into rather than adding them to this list.
|
||||
_ => false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue