From 89fd4c307409c8fc3e48c582361d71a576b72e0e Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 19 Jul 2021 20:37:39 +0200 Subject: [PATCH] test for malformed header --- compiler/reporting/src/error/parse.rs | 28 ++++++++++++++++ compiler/reporting/tests/test_reporting.rs | 37 ++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/compiler/reporting/src/error/parse.rs b/compiler/reporting/src/error/parse.rs index 646f675580..2cc53ece7a 100644 --- a/compiler/reporting/src/error/parse.rs +++ b/compiler/reporting/src/error/parse.rs @@ -3263,6 +3263,34 @@ fn to_requires_report<'a>( } } + ERequires::Rigid(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 am partway through parsing a header, but I got stuck here:"), + alloc.region_with_subregion(surroundings, region), + alloc.concat(vec![ + alloc.reflow("I am expecting a list of rigids like "), + alloc.keyword("{}"), + alloc.reflow(" or "), + alloc.keyword("{model=>Model}"), + alloc.reflow(" next. A full "), + alloc.keyword("requires"), + alloc.reflow(" definition looks like"), + ]), + alloc + .parser_suggestion("requires {model=>Model, msg=>Msg} {main : Effect {}} ") + .indent(4), + ]); + + Report { + filename, + doc, + title: "BAD RIGIDS".to_string(), + } + } + _ => todo!("unhandled parse error {:?}", parse_problem), } } diff --git a/compiler/reporting/tests/test_reporting.rs b/compiler/reporting/tests/test_reporting.rs index 56b309a30a..0d99596a83 100644 --- a/compiler/reporting/tests/test_reporting.rs +++ b/compiler/reporting/tests/test_reporting.rs @@ -5929,6 +5929,43 @@ mod test_reporting { ) } + #[test] + fn platform_requires_rigids() { + report_header_problem_as( + indoc!( + r#" + platform folkertdev/foo + requires { main : Effect {} } + exposes [] + packages {} + imports [Task] + provides [ mainForHost ] + effects fx.Effect + { + putChar : I64 -> Effect {}, + putLine : Str -> Effect {}, + getLine : Effect Str + } + "# + ), + indoc!( + r#" + ── WEIRD PROVIDES ────────────────────────────────────────────────────────────── + + I am partway through parsing a provides list, but I got stuck here: + + 3│ imports [base.Task, Base64 ] + 4│ provides [ main, @Foo ] to base + ^ + + I was expecting a type name, value name or function name next, like + + provides [ Animal, default, tame ] + "# + ), + ) + } + #[test] fn exposes_identifier() { report_header_problem_as(