Print type annotation in all type errors related to annotations

This commit is contained in:
ayazhafiz 2021-11-20 23:48:45 -05:00
parent 62873fed81
commit 8f1878bc42
2 changed files with 13 additions and 17 deletions

View File

@ -313,7 +313,7 @@ fn to_expr_report<'b>(
None => (alloc.text("this"), alloc.nil()),
};
let mut sub_region = None;
let ann_region = annotation_source.region();
let thing = match annotation_source {
TypedIfBranch {
@ -342,14 +342,11 @@ fn to_expr_report<'b>(
alloc.keyword("when"),
alloc.text(" expression:"),
]),
TypedBody { region: ann_region } => {
sub_region = Some(ann_region);
alloc.concat(vec![
alloc.text("body of "),
the_name_text,
alloc.text(" definition:"),
])
}
TypedBody { region: _ } => alloc.concat(vec![
alloc.text("body of "),
the_name_text,
alloc.text(" definition:"),
]),
};
let it_is = match annotation_source {
@ -376,14 +373,11 @@ fn to_expr_report<'b>(
filename,
doc: alloc.stack(vec![
alloc.text("Something is off with the ").append(thing),
match sub_region {
None => alloc.region(expr_region),
Some(ann_region) => {
// for typed bodies, include the line(s) with the signature
let joined =
roc_region::all::Region::span_across(&ann_region, &expr_region);
alloc.region_with_subregion(joined, expr_region)
}
{
// for typed bodies, include the line(s) with the signature
let joined =
roc_region::all::Region::span_across(&ann_region, &expr_region);
alloc.region_with_subregion(joined, expr_region)
},
comparison,
]),

View File

@ -1245,6 +1245,7 @@ mod test_reporting {
Something is off with the `then` branch of this `if` expression:
1 x : Int *
2 x = if True then 3.14 else 4
^^^^
@ -1864,6 +1865,7 @@ mod test_reporting {
Something is off with the `else` branch of this `if` expression:
1 f : a, b -> a
2 f = \x, y -> if True then x else y
^