This commit is contained in:
Joshua Warner 2024-12-22 08:02:44 -05:00
parent 7a7f8340b9
commit 24ebcf68d1
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD

View file

@ -1358,14 +1358,46 @@ impl<'a> Nodify<'a> for TypeAnnotation<'a> {
}); });
maybe_add_ext(arena, coll, ext) maybe_add_ext(arena, coll, ext)
} }
_ => { TypeAnnotation::Where(annot, implements_clauses) => {
let lifted = ann_lift_spaces(arena, self); let mut items = Vec::with_capacity_in(implements_clauses.len() + 2, arena);
let annot = annot
.value
.to_node(arena)
.add_parens(arena, Parens::InAsPattern);
items.push(Item {
comma_before: false,
before: annot.after,
newline: false,
space: true,
node: Node::Literal(roc_parse::keyword::WHERE),
});
let mut last_after: &[CommentOrNewline<'_>] = &[];
for (i, clause) in implements_clauses.iter().enumerate() {
let node = clause.value.to_node(arena);
let before = merge_spaces_conservative(arena, last_after, node.before);
items.push(Item {
before,
comma_before: i > 0,
newline: false,
space: true,
node: node.node,
});
}
NodeInfo { NodeInfo {
before: lifted.before, before: annot.before,
node: Node::TypeAnnotation(lifted.item), node: Node::Sequence {
after: lifted.after, first: arena.alloc(annot.node),
extra_indent_for_rest: false,
rest: arena.alloc_slice_copy(&items),
},
after: &[],
needs_indent: true, needs_indent: true,
prec: ann_prec(self), prec: Prec::Term,
} }
} }
} }