Print all argument in tags when their argument lengths mismatch

Closes #3553
This commit is contained in:
Ayaz Hafiz 2022-08-09 12:46:53 -07:00
parent 8c87ae50c9
commit d2015d51f2
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
2 changed files with 37 additions and 9 deletions

View File

@ -2888,15 +2888,14 @@ fn diff_record<'b>(
}
}
fn diff_tag_union<'b>(
fn same_tag_name_overlap_diff<'b>(
alloc: &'b RocDocAllocator<'b>,
fields1: &SendMap<TagName, Vec<ErrorType>>,
ext1: TypeExt,
fields2: &SendMap<TagName, Vec<ErrorType>>,
ext2: TypeExt,
) -> Diff<RocDocBuilder<'b>> {
let to_overlap_docs = |(field, (t1, t2)): (TagName, (Vec<ErrorType>, Vec<ErrorType>))| {
let diff = traverse(alloc, Parens::InTypeParam, t1, t2);
field: TagName,
args1: Vec<ErrorType>,
args2: Vec<ErrorType>,
) -> Diff<(TagName, RocDocBuilder<'b>, Vec<RocDocBuilder<'b>>)> {
if args1.len() == args2.len() {
let diff = traverse(alloc, Parens::InTypeParam, args1, args2);
Diff {
left: (field.clone(), alloc.tag_name(field.clone()), diff.left),
@ -2905,6 +2904,35 @@ fn diff_tag_union<'b>(
left_able: diff.left_able,
right_able: diff.right_able,
}
} else {
let (left_doc, left_able): (_, Vec<AbleVariables>) = args1
.into_iter()
.map(|arg| to_doc(alloc, Parens::InTypeParam, arg))
.unzip();
let (right_doc, right_able): (_, Vec<AbleVariables>) = args2
.into_iter()
.map(|arg| to_doc(alloc, Parens::InTypeParam, arg))
.unzip();
Diff {
left: (field.clone(), alloc.tag_name(field.clone()), left_doc),
right: (field.clone(), alloc.tag_name(field), right_doc),
status: Status::Similar,
left_able: left_able.into_iter().flatten().collect(),
right_able: right_able.into_iter().flatten().collect(),
}
}
}
fn diff_tag_union<'b>(
alloc: &'b RocDocAllocator<'b>,
fields1: &SendMap<TagName, Vec<ErrorType>>,
ext1: TypeExt,
fields2: &SendMap<TagName, Vec<ErrorType>>,
ext2: TypeExt,
) -> Diff<RocDocBuilder<'b>> {
let to_overlap_docs = |(field, (t1, t2)): (TagName, (Vec<ErrorType>, Vec<ErrorType>))| {
same_tag_name_overlap_diff(alloc, field, t1, t2)
};
let to_unknown_docs = |(field, args): (&TagName, &Vec<ErrorType>)| -> (
TagName,

View File

@ -10342,7 +10342,7 @@ All branches in an `if` must have the same type!
But the branch patterns have type:
[Bad [DecodeProblem], Good (List U8)]
[Bad [DecodeProblem], Good (List U8) a]
The branches must be cases of the `when` condition's type!
"###