Merge pull request #7050 from roc-lang/arg-patterns-as

This commit is contained in:
Agus Zubiaga 2024-09-02 14:02:17 -03:00 committed by GitHub
commit 2469a3aa2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 179 additions and 1 deletions

View file

@ -38,6 +38,7 @@ pub enum Parens {
InFunctionType,
InApply,
InOperator,
InAsPattern,
}
/// In an AST node, do we show newlines around it

View file

@ -1245,7 +1245,7 @@ fn fmt_closure<'a>(
let mut it = loc_patterns.iter().peekable();
while let Some(loc_pattern) = it.next() {
loc_pattern.format(buf, indent);
loc_pattern.format_with_options(buf, Parens::InAsPattern, Newlines::No, indent);
if it.peek().is_some() {
buf.indent(indent);

View file

@ -244,9 +244,19 @@ impl<'a> Formattable for Pattern<'a> {
}
As(pattern, pattern_as) => {
let needs_parens = parens == Parens::InAsPattern;
if needs_parens {
buf.push('(');
}
fmt_pattern(buf, &pattern.value, indent, parens);
pattern_as.format(buf, indent + INDENT);
if needs_parens {
buf.push(')');
}
}
// Space