mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Report module params parse error
This commit is contained in:
parent
5b1a3c8f03
commit
760ffaf68f
7 changed files with 74 additions and 1 deletions
|
@ -6210,6 +6210,31 @@ In roc, functions are always written as a lambda, like{}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn module_params_with_missing_arrow() {
|
||||||
|
report_header_problem_as(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
module {echo, read} [menu]
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
── WEIRD MODULE PARAMS in /code/proj/Main.roc ──────────────────────────────────
|
||||||
|
|
||||||
|
I am partway through parsing a module header, but I got stuck here:
|
||||||
|
|
||||||
|
1│ module {echo, read} [menu]
|
||||||
|
^
|
||||||
|
|
||||||
|
I am expecting `->` next, like:
|
||||||
|
|
||||||
|
module { echo, read } -> [menu]
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn platform_requires_rigids() {
|
fn platform_requires_rigids() {
|
||||||
report_header_problem_as(
|
report_header_problem_as(
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Header(Params(Arrow(@22), @7))
|
|
@ -0,0 +1 @@
|
||||||
|
module { echo, name } [menu]
|
|
@ -0,0 +1 @@
|
||||||
|
Header(Params(Pattern(End(@20), @7), @7))
|
|
@ -0,0 +1 @@
|
||||||
|
module { echo, name -> [menu]
|
|
@ -249,6 +249,8 @@ mod test_snapshots {
|
||||||
fail/when_over_indented_underscore.expr,
|
fail/when_over_indented_underscore.expr,
|
||||||
fail/where_type_variable.expr,
|
fail/where_type_variable.expr,
|
||||||
fail/wild_case_arrow.expr,
|
fail/wild_case_arrow.expr,
|
||||||
|
fail/module_with_unfinished_params.header,
|
||||||
|
fail/module_params_with_missing_arrow.header,
|
||||||
malformed/bad_opaque_ref.expr,
|
malformed/bad_opaque_ref.expr,
|
||||||
malformed/malformed_ident_due_to_underscore.expr,
|
malformed/malformed_ident_due_to_underscore.expr,
|
||||||
malformed/malformed_pattern_field_access.expr, // See https://github.com/roc-lang/roc/issues/399
|
malformed/malformed_pattern_field_access.expr, // See https://github.com/roc-lang/roc/issues/399
|
||||||
|
|
|
@ -3392,7 +3392,7 @@ fn to_header_report<'a>(
|
||||||
to_provides_report(alloc, lines, filename, provides, *pos)
|
to_provides_report(alloc, lines, filename, provides, *pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
EHeader::Params(_params, _pos) => todo!(),
|
EHeader::Params(params, pos) => to_params_report(alloc, lines, filename, params, *pos),
|
||||||
|
|
||||||
EHeader::Exposes(exposes, pos) => to_exposes_report(alloc, lines, filename, exposes, *pos),
|
EHeader::Exposes(exposes, pos) => to_exposes_report(alloc, lines, filename, exposes, *pos),
|
||||||
|
|
||||||
|
@ -3788,6 +3788,48 @@ fn to_provides_report<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_params_report<'a>(
|
||||||
|
alloc: &'a RocDocAllocator<'a>,
|
||||||
|
lines: &LineInfo,
|
||||||
|
filename: PathBuf,
|
||||||
|
parse_problem: &roc_parse::parser::EParams<'a>,
|
||||||
|
start: Position,
|
||||||
|
) -> Report<'a> {
|
||||||
|
use roc_parse::parser::EParams;
|
||||||
|
|
||||||
|
match parse_problem {
|
||||||
|
EParams::Pattern(error, pos) => to_precord_report(alloc, lines, filename, error, *pos),
|
||||||
|
|
||||||
|
EParams::BeforeArrow(pos) | EParams::Arrow(pos) | EParams::AfterArrow(pos) => {
|
||||||
|
let surroundings = Region::new(start, *pos);
|
||||||
|
let region = LineColumnRegion::from_pos(lines.convert_pos(*pos));
|
||||||
|
|
||||||
|
let doc = alloc.stack([
|
||||||
|
alloc
|
||||||
|
.reflow(r"I am partway through parsing a module header, but I got stuck here:"),
|
||||||
|
alloc.region_with_subregion(lines.convert_region(surroundings), region),
|
||||||
|
alloc.concat([
|
||||||
|
alloc.reflow("I am expecting "),
|
||||||
|
alloc.keyword("->"),
|
||||||
|
alloc.reflow(" next, like:"),
|
||||||
|
]),
|
||||||
|
alloc
|
||||||
|
.parser_suggestion("module { echo, read } -> [menu]")
|
||||||
|
.indent(4),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Report {
|
||||||
|
filename,
|
||||||
|
doc,
|
||||||
|
title: "WEIRD MODULE PARAMS".to_string(),
|
||||||
|
severity: Severity::RuntimeError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EParams::Space(error, pos) => to_space_report(alloc, lines, filename, error, *pos),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn to_exposes_report<'a>(
|
fn to_exposes_report<'a>(
|
||||||
alloc: &'a RocDocAllocator<'a>,
|
alloc: &'a RocDocAllocator<'a>,
|
||||||
lines: &LineInfo,
|
lines: &LineInfo,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue