empty or pattern message

This commit is contained in:
Folkert 2021-02-20 16:44:29 +01:00
parent 576b7974e8
commit a6fbf55390
2 changed files with 49 additions and 2 deletions

View file

@ -198,6 +198,7 @@ fn to_when_report<'a>(
} }
_ => to_syntax_report(alloc, filename, nested, row, col), _ => to_syntax_report(alloc, filename, nested, row, col),
}, },
When::Pattern(ref pat, row, col) => to_pattern_report(alloc, filename, pat, row, col),
_ => todo!("unhandled parse error: {:?}", parse_problem), _ => todo!("unhandled parse error: {:?}", parse_problem),
} }
} }
@ -206,12 +207,28 @@ fn to_pattern_report<'a>(
alloc: &'a RocDocAllocator<'a>, alloc: &'a RocDocAllocator<'a>,
filename: PathBuf, filename: PathBuf,
parse_problem: &roc_parse::parser::EPattern<'a>, parse_problem: &roc_parse::parser::EPattern<'a>,
_start_row: Row, start_row: Row,
_start_col: Col, start_col: Col,
) -> Report<'a> { ) -> Report<'a> {
use roc_parse::parser::EPattern; use roc_parse::parser::EPattern;
match parse_problem { match parse_problem {
EPattern::Start(row, col) => {
let surroundings = Region::from_rows_cols(start_row, start_col, *row, *col);
let region = Region::from_row_col(*row, *col);
let doc = alloc.stack(vec![
alloc.reflow(r"I just started parsing a pattern, but I got stuck here:"),
alloc.region_with_subregion(surroundings, region),
alloc.note("I may be confused by indentation"),
]);
Report {
filename,
doc,
title: "UNFINISHED PATTERN".to_string(),
}
}
EPattern::Record(record, row, col) => { EPattern::Record(record, row, col) => {
to_precord_report(alloc, filename, &record, *row, *col) to_precord_report(alloc, filename, &record, *row, *col)
} }

View file

@ -4774,6 +4774,7 @@ mod test_reporting {
), ),
) )
} }
#[test] #[test]
fn if_guard_without_condition() { fn if_guard_without_condition() {
// this should get better with time // this should get better with time
@ -4804,6 +4805,35 @@ mod test_reporting {
) )
} }
#[test]
fn empty_or_pattern() {
// this should get better with time
report_problem_as(
indoc!(
r#"
when Just 4 is
Just 4 | ->
4
_ ->
2
"#
),
indoc!(
r#"
UNFINISHED PATTERN
I just started parsing a pattern, but I got stuck here:
2 Just 4 | ->
^
Note: I may be confused by indentation
"#
),
)
}
#[test] #[test]
#[ignore] #[ignore]
fn pattern_binds_keyword() { fn pattern_binds_keyword() {