mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Nicer message for unhandled expr errors
This commit is contained in:
parent
b9a693c077
commit
160dbee943
2 changed files with 91 additions and 23 deletions
|
@ -5821,6 +5821,36 @@ mod test_reporting {
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
unhandled_parse_error,
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
app "test" provides [main] to "./platform"
|
||||||
|
|
||||||
|
42
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
@r#"
|
||||||
|
── UNHANDLED PARSE ERROR in tmp/unhandled_parse_error/Test.roc ─────────────────
|
||||||
|
|
||||||
|
I got stuck while parsing this:
|
||||||
|
|
||||||
|
1│ app "test" provides [main] to "./platform"
|
||||||
|
2│
|
||||||
|
3│ 42
|
||||||
|
^
|
||||||
|
|
||||||
|
Here's the internal parse problem:
|
||||||
|
|
||||||
|
UnexpectedTopLevelExpr(@44)
|
||||||
|
|
||||||
|
Unfortunately, I'm not able to provide a more insightful error message
|
||||||
|
for this syntax problem yet. This is considered a bug in the compiler.
|
||||||
|
|
||||||
|
Note: If you'd like to contribute to Roc, this would be a good first issue!
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
|
||||||
// https://github.com/roc-lang/roc/issues/1714
|
// https://github.com/roc-lang/roc/issues/1714
|
||||||
test_report!(
|
test_report!(
|
||||||
interpolate_concat_is_transparent_1714,
|
interpolate_concat_is_transparent_1714,
|
||||||
|
|
|
@ -703,30 +703,68 @@ fn to_expr_report<'a>(
|
||||||
EExpr::Return(EReturn::Space(parse_problem, pos), _) => {
|
EExpr::Return(EReturn::Space(parse_problem, pos), _) => {
|
||||||
to_space_report(alloc, lines, filename, parse_problem, *pos)
|
to_space_report(alloc, lines, filename, parse_problem, *pos)
|
||||||
}
|
}
|
||||||
EExpr::End(_)
|
// If you're adding or changing syntax, please handle the case with a good error message
|
||||||
| EExpr::Dot(_)
|
// above instead of adding more unhandled cases below.
|
||||||
| EExpr::Access(_)
|
EExpr::End(pos)
|
||||||
| EExpr::UnaryNot(_)
|
| EExpr::Dot(pos)
|
||||||
| EExpr::UnaryNegate(_)
|
| EExpr::Access(pos)
|
||||||
| EExpr::Pattern(_, _)
|
| EExpr::UnaryNot(pos)
|
||||||
| EExpr::IndentDefBody(_)
|
| EExpr::UnaryNegate(pos)
|
||||||
| EExpr::IndentEquals(_)
|
| EExpr::Pattern(_, pos)
|
||||||
| EExpr::IndentAnnotation(_)
|
| EExpr::IndentDefBody(pos)
|
||||||
| EExpr::Equals(_)
|
| EExpr::IndentEquals(pos)
|
||||||
| EExpr::DoubleColon(_)
|
| EExpr::IndentAnnotation(pos)
|
||||||
| EExpr::MalformedPattern(_)
|
| EExpr::Equals(pos)
|
||||||
| EExpr::BackpassComma(_)
|
| EExpr::DoubleColon(pos)
|
||||||
| EExpr::BackpassContinue(_)
|
| EExpr::MalformedPattern(pos)
|
||||||
| EExpr::DbgContinue(_)
|
| EExpr::BackpassComma(pos)
|
||||||
| EExpr::Underscore(_)
|
| EExpr::BackpassContinue(pos)
|
||||||
| EExpr::Crash(_)
|
| EExpr::DbgContinue(pos)
|
||||||
| EExpr::Try(_)
|
| EExpr::Underscore(pos)
|
||||||
| EExpr::RecordUpdateOldBuilderField(_)
|
| EExpr::Crash(pos)
|
||||||
| EExpr::RecordUpdateIgnoredField(_)
|
| EExpr::Try(pos)
|
||||||
| EExpr::RecordBuilderOldBuilderField(_)
|
| EExpr::UnexpectedTopLevelExpr(pos) => {
|
||||||
| EExpr::UnexpectedTopLevelExpr(_) => {
|
to_unhandled_parse_error_report(alloc, lines, filename, parse_problem, *pos, start)
|
||||||
todo!("unhandled parse error: {:?}", parse_problem)
|
|
||||||
}
|
}
|
||||||
|
EExpr::RecordUpdateOldBuilderField(region)
|
||||||
|
| EExpr::RecordUpdateIgnoredField(region)
|
||||||
|
| EExpr::RecordBuilderOldBuilderField(region) => to_unhandled_parse_error_report(
|
||||||
|
alloc,
|
||||||
|
lines,
|
||||||
|
filename,
|
||||||
|
parse_problem,
|
||||||
|
region.start(),
|
||||||
|
start,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_unhandled_parse_error_report<'a>(
|
||||||
|
alloc: &'a RocDocAllocator<'a>,
|
||||||
|
lines: &LineInfo,
|
||||||
|
filename: PathBuf,
|
||||||
|
parse_problem: &roc_parse::parser::EExpr<'a>,
|
||||||
|
pos: Position,
|
||||||
|
start: Position,
|
||||||
|
) -> Report<'a> {
|
||||||
|
let severity = Severity::Fatal;
|
||||||
|
let surroundings = Region::new(start, pos);
|
||||||
|
let region = LineColumnRegion::from_pos(lines.convert_pos(pos));
|
||||||
|
|
||||||
|
let doc = alloc.stack([
|
||||||
|
alloc.reflow("I got stuck while parsing this:"),
|
||||||
|
alloc.region_with_subregion(lines.convert_region(surroundings), region, severity),
|
||||||
|
alloc.reflow("Here's the internal parse problem:"),
|
||||||
|
alloc.text(format!("{:?}", parse_problem)).indent(4),
|
||||||
|
alloc.reflow("Unfortunately, I'm not able to provide a more insightful error message for this syntax problem yet. This is considered a bug in the compiler."),
|
||||||
|
alloc.note("If you'd like to contribute to Roc, this would be a good first issue!")
|
||||||
|
]);
|
||||||
|
|
||||||
|
Report {
|
||||||
|
filename,
|
||||||
|
doc,
|
||||||
|
title: "UNHANDLED PARSE ERROR".to_string(),
|
||||||
|
severity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue