Merge remote-tracking branch 'remote/main' into builtin-task

This commit is contained in:
Luke Boswell 2024-07-29 16:05:51 +10:00
commit eca453d07f
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
367 changed files with 14084 additions and 12080 deletions

View file

@ -203,7 +203,7 @@ fn to_expr_report<'a>(
alloc.region_with_subregion(lines.convert_region(surroundings), region, severity),
alloc.concat([
alloc.reflow("Looks like you are trying to define a function. "),
alloc.reflow("In roc, functions are always written as a lambda, like "),
alloc.reflow("In Roc, functions are always written as a lambda, like "),
alloc.parser_suggestion("increment = \\n -> n + 1"),
alloc.reflow("."),
]),
@ -257,7 +257,7 @@ fn to_expr_report<'a>(
Context::InDef(_pos) => {
vec![alloc.stack([
alloc.reflow("Looks like you are trying to define a function. "),
alloc.reflow("In roc, functions are always written as a lambda, like "),
alloc.reflow("In Roc, functions are always written as a lambda, like "),
alloc
.parser_suggestion("increment = \\n -> n + 1")
.indent(4),
@ -509,7 +509,7 @@ fn to_expr_report<'a>(
alloc.region_with_subregion(lines.convert_region(surroundings), region, severity),
alloc.concat([
alloc.reflow("Looks like you are trying to define a function. "),
alloc.reflow("In roc, functions are always written as a lambda, like "),
alloc.reflow("In Roc, functions are always written as a lambda, like "),
alloc.parser_suggestion("increment = \\n -> n + 1"),
alloc.reflow("."),
]),
@ -695,6 +695,29 @@ fn to_expr_report<'a>(
severity,
}
}
EExpr::StmtAfterExpr(pos) => {
let surroundings = Region::new(start, *pos);
let region = LineColumnRegion::from_pos(lines.convert_pos(*pos));
let doc = alloc.stack([
alloc
.reflow(r"I just finished parsing an expression with a series of definitions,"),
alloc.reflow(
r"and this line is indented as if it's intended to be part of that expression:",
),
alloc.region_with_subregion(lines.convert_region(surroundings), region, severity),
alloc.concat([alloc.reflow(
"However, I already saw the final expression in that series of definitions.",
)]),
]);
Report {
filename,
doc,
title: "STATEMENT AFTER EXPRESSION".to_string(),
severity,
}
}
_ => todo!("unhandled parse error: {:?}", parse_problem),
}
}
@ -1518,7 +1541,7 @@ fn to_import_report<'a>(
alloc.concat([
alloc.reflow("I was expecting to see the "),
alloc.keyword("as"),
alloc.reflow(" keyword, like:"),
alloc.reflow(" keyword next, like:"),
]),
alloc
.parser_suggestion("import svg.Path as SvgPath")

View file

@ -675,9 +675,24 @@ fn to_expr_report<'b>(
}
}
Expected::FromAnnotation(name, _arity, annotation_source, expected_type) => {
use roc_can::pattern::Pattern;
use roc_types::types::AnnotationSource::*;
let is_suffixed = match &name.value {
Pattern::Identifier(symbol) => symbol.as_str(alloc.interns).starts_with("#!"),
_ => false,
};
let is_suffixed_stmt = match &name.value {
Pattern::Identifier(symbol) => {
let ident = symbol.as_str(alloc.interns);
ident.starts_with("#!") && ident.ends_with("_stmt")
}
_ => false,
};
let (the_name_text, on_name_text) = match pattern_to_doc(alloc, &name.value) {
_ if is_suffixed => (alloc.text("this suffixed"), alloc.nil()),
Some(doc) => (
alloc.concat([alloc.reflow("the "), doc.clone()]),
alloc.concat([alloc.reflow(" on "), doc]),
@ -714,6 +729,11 @@ fn to_expr_report<'b>(
alloc.keyword("when"),
alloc.text(" expression:"),
]),
TypedBody { .. } if is_suffixed_stmt => alloc.concat([
alloc.text("body of "),
the_name_text,
alloc.text(" statement:"),
]),
TypedBody { .. } => alloc.concat([
alloc.text("body of "),
the_name_text,
@ -769,11 +789,18 @@ fn to_expr_report<'b>(
expected_type,
expectation_context,
add_category(alloc, alloc.text(it_is), &category),
alloc.concat([
alloc.text("But the type annotation"),
on_name_text,
alloc.text(" says it should be:"),
]),
if is_suffixed_stmt {
// TODO: add a tip for using underscore
alloc.text(
"But a suffixed statement is expected to resolve to an empty record:",
)
} else {
alloc.concat([
alloc.text("But the type annotation"),
on_name_text,
alloc.text(" says it should be:"),
])
},
None,
)
};