Relax implements handling in patterns

This commit is contained in:
Joshua Warner 2024-12-15 16:58:31 -08:00
parent d6d396b887
commit 4a19926425
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 62 additions and 6 deletions

View file

@ -155,11 +155,7 @@ fn fmt_pattern_only(
match me {
Pattern::Identifier { ident } => {
buf.indent(indent);
if *ident == "implements" {
buf.push_str("(implements)");
} else {
snakify_camel_ident(buf, ident);
}
snakify_camel_ident(buf, ident);
}
Pattern::Tag(name) | Pattern::OpaqueRef(name) => {
buf.indent(indent);
@ -520,7 +516,16 @@ pub fn pattern_fmt_apply(
buf.ensure_ends_with_newline();
}
fmt_pattern_only(&arg.item, buf, parens, indent_more, arg.item.is_multiline());
if matches!(
arg.item,
Pattern::Identifier {
ident: "implements"
}
) {
buf.push_str("(implements)");
} else {
fmt_pattern_only(&arg.item, buf, parens, indent_more, arg.item.is_multiline());
}
last_after = arg.after;

View file

@ -0,0 +1,46 @@
@0-16 SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-14,
],
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: [
Body(
@0-12 RecordDestructure(
[
@1-11 Identifier {
ident: "implements",
},
],
),
@13-14 Var {
module_name: "",
ident: "d",
},
),
],
},
@15-16 SpaceBefore(
Tag(
"I",
),
[
Newline,
],
),
),
[
Newline,
],
)

View file

@ -0,0 +1,2 @@
{implements}=d
I

View file

@ -442,6 +442,7 @@ mod test_snapshots {
pass/implements_newline_in_fn_ty.expr,
pass/implements_newlines_comments.expr,
pass/implements_not_keyword.expr,
pass/implements_record_destructure.expr,
pass/import.moduledefs,
pass/import_from_package.moduledefs,
pass/import_in_closure_with_curlies_after.expr,