Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions crates/compiler/load/tests/test_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5982,6 +5982,60 @@ In roc, functions are always written as a lambda, like{}
)
}

#[test]
fn provides_missing_to_in_app_header() {
report_header_problem_as(
indoc!(
r#"
app "broken"
provides [main]
"#
),
indoc!(
r#"
── WEIRD PROVIDES ──────────────────────────────────────── /code/proj/Main.roc ─

I am partway through parsing a header, but I got stuck here:

1│ app "broken"
2│ provides [main]
^

I am expecting the `to` keyword next, like:

to pf
"#
),
)
}

#[test]
fn provides_to_missing_platform_in_app_header() {
report_header_problem_as(
indoc!(
r#"
app "broken"
provides [main] to
"#
),
indoc!(
r#"
── WEIRD PROVIDES ──────────────────────────────────────── /code/proj/Main.roc ─

I am partway through parsing a header, but I got stuck here:

1│ app "broken"
2│ provides [main] to
^

I am expecting the platform name next, like:

to pf
"#
),
)
}

#[test]
fn platform_requires_rigids() {
report_header_problem_as(
Expand Down
46 changes: 46 additions & 0 deletions crates/reporting/src/error/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3515,6 +3515,52 @@ fn to_provides_report<'a>(

EProvides::Space(error, pos) => to_space_report(alloc, lines, filename, &error, pos),

EProvides::IndentTo(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 header, but I got stuck here:"),
alloc.region_with_subregion(lines.convert_region(surroundings), region),
alloc.concat([
alloc.reflow("I am expecting the "),
alloc.keyword("to"),
alloc.reflow(" keyword next, like:"),
]),
alloc
.parser_suggestion("to pf")
.indent(4),
]);

Report {
filename,
doc,
title: "WEIRD PROVIDES".to_string(),
severity: Severity::RuntimeError,
}
}

EProvides::IndentListStart(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 header, but I got stuck here:"),
alloc.region_with_subregion(lines.convert_region(surroundings), region),
alloc.reflow("I am expecting the platform name next, like:"),
alloc
.parser_suggestion("to pf")
.indent(4),
]);

Report {
filename,
doc,
title: "WEIRD PROVIDES".to_string(),
severity: Severity::RuntimeError,
}
}

_ => todo!("unhandled parse error {:?}", parse_problem),
}
}
Expand Down