Report exposing list end error in imports

This commit is contained in:
Agus Zubiaga 2024-05-06 23:38:12 -03:00
parent dc18597a0e
commit 755e16cb10
No known key found for this signature in database
2 changed files with 41 additions and 2 deletions

View file

@ -5024,6 +5024,26 @@ mod test_reporting {
I just saw the `exposing` keyword, so I was expecting to see `[` next. I just saw the `exposing` keyword, so I was expecting to see `[` next.
"###); "###);
test_report!(
unfinished_import_exposing_name,
indoc!(
r"
import svg.Path exposing [3
"
),
@r###"
WEIRD EXPOSING in tmp/unfinished_import_exposing_name/Test.roc
I'm partway through parsing an exposing list, but I got stuck here:
4 import svg.Path exposing [3
^
I was expecting a type, value, or function name next, like:
import Svg exposing [Path, arc, rx]
"###);
test_report!( test_report!(
ingested_file_import_ann_syntax_err, ingested_file_import_ann_syntax_err,
indoc!( indoc!(

View file

@ -1545,8 +1545,27 @@ fn to_import_report<'a>(
alloc.reflow(" next."), alloc.reflow(" next."),
]), ]),
), ),
ExposedName(_) => todo!(), ExposedName(pos) | ExposingListEnd(pos) => {
ExposingListEnd(_) => todo!(), let surroundings = Region::new(start, *pos);
let region = LineColumnRegion::from_pos(lines.convert_pos(*pos));
let doc = alloc.stack([
alloc
.reflow(r"I'm partway through parsing an exposing list, but I got stuck here:"),
alloc.region_with_subregion(lines.convert_region(surroundings), region),
alloc.reflow(r"I was expecting a type, value, or function name next, like:"),
alloc
.parser_suggestion("import Svg exposing [Path, arc, rx]")
.indent(4),
]);
Report {
filename,
doc,
title: "WEIRD EXPOSING".to_string(),
severity: Severity::RuntimeError,
}
}
IndentIngestedName(_) => todo!(), IndentIngestedName(_) => todo!(),
IngestedName(_) => todo!(), IngestedName(_) => todo!(),
IndentAnnotation(_) => todo!(), IndentAnnotation(_) => todo!(),