Generalize RecordAccess special-cases to include TupleAccess

This commit is contained in:
Joshua Warner 2024-12-12 19:59:14 -08:00
parent d66f51db7b
commit 5a6e0f546b
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 68 additions and 2 deletions

View file

@ -614,7 +614,9 @@ fn requires_space_after_unary(item: &Expr<'_>) -> bool {
is_negative,
} => *is_negative,
Expr::RecordUpdater(..) => true,
Expr::RecordAccess(inner, _field) => requires_space_after_unary(inner),
Expr::RecordAccess(inner, _field) | Expr::TupleAccess(inner, _field) => {
requires_space_after_unary(inner)
}
Expr::Apply(inner, _, _) => requires_space_after_unary(&inner.value),
Expr::TrySuffix { target: _, expr } => requires_space_after_unary(expr),
Expr::SpaceAfter(inner, _) | Expr::SpaceBefore(inner, _) => {

View file

@ -0,0 +1,54 @@
@0-9 SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-1,
],
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: [
Stmt(
@0-1 Tag(
"J",
),
),
],
},
@2-9 SpaceBefore(
UnaryOp(
@4-6 SpaceBefore(
TupleAccess(
TrySuffix {
target: Task,
expr: AccessorFunction(
TupleIndex(
"1",
),
),
},
"0",
),
[
Newline,
],
),
@2-3 Not,
),
[
Newline,
],
),
),
[
Newline,
],
)

View file

@ -316,6 +316,7 @@ mod test_snapshots {
pass/backpassing_bananza.expr,
pass/backpassing_in_parens_in_tuple.expr,
pass/bang_newline_double_accessor.expr,
pass/bangs_and_tuple_accessors.expr,
pass/basic_apply.expr,
pass/basic_docs.expr,
pass/basic_field.expr,
@ -715,7 +716,11 @@ mod test_snapshots {
// This is the current list as of writing.
// We should be driving these down to zero over time.
// Adding this protection in now to avoid accidentally adding more.
"all_the_bangs" => true,
"all_the_bangs" | "bangs_and_tuple_accessors" => {
// both of these result in:
// "a Expr::TrySuffix expression was not completely removed in desugar_value_def_suffixed"
true
}
// When adding new snapshot tests, strongly prefer fixing any canonicalization panics
// they may run into rather than adding them to this list.