diff --git a/compiler/reporting/src/error/mono.rs b/compiler/reporting/src/error/mono.rs index 5011801850..6e7cfac805 100644 --- a/compiler/reporting/src/error/mono.rs +++ b/compiler/reporting/src/error/mono.rs @@ -122,6 +122,14 @@ pub fn unhandled_patterns_to_doc_block<'b>( fn pattern_to_doc<'b>( alloc: &'b RocDocAllocator<'b>, pattern: roc_mono::pattern::Pattern, +) -> RocDocBuilder<'b> { + pattern_to_doc_help(alloc, pattern, false) +} + +fn pattern_to_doc_help<'b>( + alloc: &'b RocDocAllocator<'b>, + pattern: roc_mono::pattern::Pattern, + in_type_param: bool, ) -> RocDocBuilder<'b> { use roc_mono::pattern::Literal::*; use roc_mono::pattern::Pattern::*; @@ -137,7 +145,10 @@ fn pattern_to_doc<'b>( Str(s) => alloc.string(s.into()), }, Ctor(union, tag_id, args) => { - let arg_docs = args.into_iter().map(|v| pattern_to_doc(alloc, v)); + let has_args = !args.is_empty(); + let arg_docs = args + .into_iter() + .map(|v| pattern_to_doc_help(alloc, v, true)); let tag = &union.alternatives[tag_id.0 as usize]; let tag_name = tag.name.clone(); @@ -147,7 +158,14 @@ fn pattern_to_doc<'b>( let docs = std::iter::once(alloc.tag_name(tag_name)).chain(arg_docs); - alloc.intersperse(docs, alloc.space()) + if in_type_param && has_args { + alloc + .text("(") + .append(alloc.intersperse(docs, alloc.space())) + .append(")") + } else { + alloc.intersperse(docs, alloc.space()) + } } } } diff --git a/compiler/reporting/tests/test_reporting.rs b/compiler/reporting/tests/test_reporting.rs index cdb010d4a2..0ac724f127 100644 --- a/compiler/reporting/tests/test_reporting.rs +++ b/compiler/reporting/tests/test_reporting.rs @@ -2299,7 +2299,7 @@ mod test_reporting { Other possibilities include: - #Record Just _ _ + #Record (Just _) _ I would have to crash if I saw one of those! Add branches for them! "# @@ -2329,7 +2329,7 @@ mod test_reporting { Other possibilities include: - Record Just _ _ + Record (Just _) _ I would have to crash if I saw one of those! Add branches for them! "#