fix ! bug for Record and Tuple Access

This commit is contained in:
Luke Boswell 2024-04-02 14:17:22 +11:00
parent a28cd251ab
commit 584d41f621
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
2 changed files with 68 additions and 19 deletions

View file

@ -503,14 +503,38 @@ impl<'a> Formattable for Expr<'a> {
}
}
RecordAccess(expr, key) => {
expr.format_with_options(buf, Parens::InApply, Newlines::Yes, indent);
// Check for any `!` suffixes and format these at the end of expression
let (expr_to_format, suffix_count) = if let Var{module_name, ident, suffixed} = expr {
(Var {module_name, ident, suffixed:0}, suffixed)
} else {
(**expr, &0u8)
};
expr_to_format.format_with_options(buf, Parens::InApply, Newlines::Yes, indent);
buf.push('.');
buf.push_str(key);
for _ in 0..*suffix_count {
buf.push('!');
}
}
TupleAccess(expr, key) => {
expr.format_with_options(buf, Parens::InApply, Newlines::Yes, indent);
// Check for any `!` suffixes and format these at the end of expression
let (expr_to_format, suffix_count) = if let Var{module_name, ident, suffixed} = expr {
(Var {module_name, ident, suffixed:0}, suffixed)
} else {
(**expr, &0u8)
};
expr_to_format.format_with_options(buf, Parens::InApply, Newlines::Yes, indent);
buf.push('.');
buf.push_str(key);
for _ in 0..*suffix_count {
buf.push('!');
}
}
MalformedIdent(str, _) => {
buf.indent(indent);