Add lifting for ext values in types

This commit is contained in:
Joshua Warner 2024-12-02 07:16:22 -08:00
parent 64164eb1f4
commit 48c941d542
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 125 additions and 0 deletions

View file

@ -885,6 +885,63 @@ pub fn ann_lift_spaces<'a, 'b: 'a>(
inner.after = merge_spaces_conservative(arena, inner.after, spaces);
inner
}
TypeAnnotation::Tuple { elems, ext } => {
if let Some(ext) = ext {
let lifted = ann_lift_spaces_after(arena, &ext.value);
Spaces {
before: &[],
item: TypeAnnotation::Tuple {
elems: *elems,
ext: Some(arena.alloc(Loc::at_zero(lifted.item))),
},
after: lifted.after,
}
} else {
Spaces {
before: &[],
item: *ann,
after: &[],
}
}
}
TypeAnnotation::Record { fields, ext } => {
if let Some(ext) = ext {
let lifted = ann_lift_spaces_after(arena, &ext.value);
Spaces {
before: &[],
item: TypeAnnotation::Record {
fields: *fields,
ext: Some(arena.alloc(Loc::at_zero(lifted.item))),
},
after: lifted.after,
}
} else {
Spaces {
before: &[],
item: *ann,
after: &[],
}
}
}
TypeAnnotation::TagUnion { ext, tags } => {
if let Some(ext) = ext {
let lifted = ann_lift_spaces_after(arena, &ext.value);
Spaces {
before: &[],
item: TypeAnnotation::TagUnion {
ext: Some(arena.alloc(Loc::at_zero(lifted.item))),
tags: *tags,
},
after: lifted.after,
}
} else {
Spaces {
before: &[],
item: *ann,
after: &[],
}
}
}
_ => Spaces {
before: &[],
item: *ann,

View file

@ -0,0 +1,59 @@
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 Identifier {
ident: "t",
},
@2-11 Tuple {
elems: [],
ext: Some(
@5-6 SpaceAfter(
BoundVariable(
"n",
),
[
LineComment(
"",
),
LineComment(
"",
),
],
),
),
},
),
],
},
@12-13 SpaceBefore(
Var {
module_name: "",
ident: "p",
},
[
Newline,
],
),
),
[
LineComment(
"",
),
],
)

View file

@ -0,0 +1,4 @@
t:()(n#
#
)
p#

View file

@ -344,6 +344,7 @@ mod test_snapshots {
pass/comment_in_backpassing_args.expr,
pass/comment_in_closure_pat.expr,
pass/comment_in_closure_pat_apply.expr,
pass/comment_in_tuple_ext.expr,
pass/comment_indent_in_parens.expr,
pass/comment_inside_empty_list.expr,
pass/comment_with_non_ascii.expr,