Skip to content

Commit

Permalink
[printer] Do not print () after variant pattern with no attached da…
Browse files Browse the repository at this point in the history
…ta (#1107)
  • Loading branch information
SamChou19815 authored Oct 16, 2023
1 parent 1084299 commit b0b8c68
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions crates/samlang-core/src/printer/source_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,18 @@ fn matching_pattern_to_document(heap: &Heap, pattern: &pattern::MatchingPattern<
tag,
data_variables,
type_: (),
}) => Document::concat(vec![
Document::Text(rc_pstr(heap, tag.name)),
parenthesis_surrounded_doc(comma_sep_list(data_variables, |(p, _)| {
matching_pattern_to_document(heap, p)
})),
]),
}) => {
if data_variables.is_empty() {
Document::Text(rc_pstr(heap, tag.name))
} else {
Document::concat(vec![
Document::Text(rc_pstr(heap, tag.name)),
parenthesis_surrounded_doc(comma_sep_list(data_variables, |(p, _)| {
matching_pattern_to_document(heap, p)
})),
])
}
}
pattern::MatchingPattern::Id(id, _) => Document::Text(rc_pstr(heap, id.name)),
pattern::MatchingPattern::Wildcard(_) => Document::Text(rcs("_")),
}
Expand Down Expand Up @@ -1358,7 +1364,7 @@ Test /* b */ /* c */.VariantName<T>(42)"#,
r#"{
let _ = if let {
foo as {
bar as [Fizz(baz), Buzz(), _],
bar as [Fizz(baz), Buzz, _],
boo
}
} = true then {
Expand Down

0 comments on commit b0b8c68

Please sign in to comment.