mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Implement lifting for abilities
This commit is contained in:
parent
4da6bb0be6
commit
7fd97dec72
5 changed files with 90 additions and 10 deletions
|
@ -155,16 +155,30 @@ pub fn tydef_lift_spaces<'a, 'b: 'a>(arena: &'a Bump, def: TypeDef<'b>) -> Space
|
|||
}
|
||||
}
|
||||
TypeDef::Ability {
|
||||
header: _,
|
||||
loc_implements: _,
|
||||
members: _,
|
||||
header,
|
||||
loc_implements,
|
||||
members,
|
||||
} => {
|
||||
// TODO: if the fuzzer ever generates examples where it's important to lift spaces from the members,
|
||||
// we'll need to implement this. I'm not sure that's possible, though.
|
||||
Spaces {
|
||||
before: &[],
|
||||
item: def,
|
||||
after: &[],
|
||||
let new_members = arena.alloc_slice_copy(members);
|
||||
if let Some(last) = new_members.last_mut() {
|
||||
let typ = ann_lift_spaces_after(arena, &last.typ.value);
|
||||
last.typ.value = typ.item;
|
||||
|
||||
Spaces {
|
||||
before: &[],
|
||||
item: TypeDef::Ability {
|
||||
header,
|
||||
loc_implements,
|
||||
members: new_members,
|
||||
},
|
||||
after: typ.after,
|
||||
}
|
||||
} else {
|
||||
Spaces {
|
||||
before: &[],
|
||||
item: def,
|
||||
after: &[],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1142,7 +1156,6 @@ impl<'a> Formattable for AbilityMember<'a> {
|
|||
buf: &mut Buf,
|
||||
_parens: Parens,
|
||||
_newlines: Newlines,
|
||||
|
||||
indent: u16,
|
||||
) {
|
||||
let Spaces { before, item, .. } = self.name.value.extract_spaces();
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
S implements i : a #
|
||||
#
|
||||
|
||||
0
|
|
@ -0,0 +1,58 @@
|
|||
@0-24 SpaceAfter(
|
||||
Defs(
|
||||
Defs {
|
||||
tags: [
|
||||
EitherIndex(0),
|
||||
],
|
||||
regions: [
|
||||
@0-22,
|
||||
],
|
||||
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: [
|
||||
Ability {
|
||||
header: TypeHeader {
|
||||
name: @0-1 "S",
|
||||
vars: [],
|
||||
},
|
||||
loc_implements: @2-12 Implements,
|
||||
members: [
|
||||
AbilityMember {
|
||||
name: @13-14 "i",
|
||||
typ: @16-17 SpaceAfter(
|
||||
BoundVariable(
|
||||
"a",
|
||||
),
|
||||
[
|
||||
LineComment(
|
||||
"",
|
||||
),
|
||||
LineComment(
|
||||
"",
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
value_defs: [],
|
||||
},
|
||||
@23-24 SpaceBefore(
|
||||
Num(
|
||||
"0",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
S implements i:(a#
|
||||
#
|
||||
)
|
||||
0
|
|
@ -458,6 +458,7 @@ mod test_snapshots {
|
|||
pass/if_in_record_field_opt_pat.expr,
|
||||
pass/if_newline_then_negate_else_recordupdater.expr,
|
||||
pass/if_then_weird_indent.expr,
|
||||
pass/implements_annotation_comment.expr,
|
||||
pass/implements_in_pat_after_comment.expr,
|
||||
pass/implements_newline_in_fn_ty.expr,
|
||||
pass/implements_newlines_comments.expr,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue