mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Revise error for reporting
This commit is contained in:
parent
930f83a283
commit
67b7be9786
2 changed files with 39 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
||||||
use crate::report::{plain_text, with_indent, Report, ReportText};
|
use crate::report::{code_text, plain_text, with_indent, Report, ReportText};
|
||||||
use roc_can::expected::{Expected, PExpected};
|
use roc_can::expected::{Expected, PExpected};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_solve::solve;
|
use roc_solve::solve;
|
||||||
|
@ -84,13 +84,13 @@ fn report_bad_type(
|
||||||
expected_type: ErrorType,
|
expected_type: ErrorType,
|
||||||
region: roc_region::all::Region,
|
region: roc_region::all::Region,
|
||||||
_opt_highlight: Option<roc_region::all::Region>,
|
_opt_highlight: Option<roc_region::all::Region>,
|
||||||
problem: &str,
|
problem: ReportText,
|
||||||
this_is: &str,
|
this_is: &str,
|
||||||
further_details: ReportText,
|
further_details: ReportText,
|
||||||
) -> Report {
|
) -> Report {
|
||||||
use ReportText::*;
|
use ReportText::*;
|
||||||
let lines = vec![
|
let lines = vec![
|
||||||
plain_text(problem),
|
problem,
|
||||||
Region(region),
|
Region(region),
|
||||||
lone_type(
|
lone_type(
|
||||||
found,
|
found,
|
||||||
|
@ -120,21 +120,40 @@ fn to_expr_report(
|
||||||
Expected::FromAnnotation(_name, _arity, _sub_context, _expected_type) => todo!(),
|
Expected::FromAnnotation(_name, _arity, _sub_context, _expected_type) => todo!(),
|
||||||
Expected::ForReason(reason, expected_type, region) => {
|
Expected::ForReason(reason, expected_type, region) => {
|
||||||
match reason {
|
match reason {
|
||||||
Reason::IfCondition => report_bad_type(
|
Reason::IfCondition => {
|
||||||
|
let problem = Concat(vec![
|
||||||
|
plain_text("This "),
|
||||||
|
code_text("if"),
|
||||||
|
plain_text(" condition should be a "),
|
||||||
|
ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)),
|
||||||
|
plain_text(", but it isn’t."),
|
||||||
|
]);
|
||||||
|
|
||||||
|
report_bad_type(
|
||||||
filename,
|
filename,
|
||||||
&category,
|
&category,
|
||||||
found,
|
found,
|
||||||
expected_type,
|
expected_type,
|
||||||
region,
|
region,
|
||||||
Some(expr_region),
|
Some(expr_region),
|
||||||
"This `if` condition does not evaluate to a boolean value, True or False.",
|
problem,
|
||||||
"It is",
|
"Instead it’s",
|
||||||
Concat(vec![
|
Concat(vec![
|
||||||
plain_text("But I need this `if` condition to be a "),
|
code_text("if"),
|
||||||
ReportText::Type(Content::Alias(Symbol::BOOL_BOOL, vec![], Variable::BOOL)),
|
plain_text(" conditions must evaluate to a "),
|
||||||
plain_text(" value."),
|
ReportText::Type(Content::Alias(
|
||||||
|
Symbol::BOOL_BOOL,
|
||||||
|
vec![],
|
||||||
|
Variable::BOOL,
|
||||||
|
)),
|
||||||
|
plain_text("—either "),
|
||||||
|
code_text("True"),
|
||||||
|
plain_text(" or "),
|
||||||
|
code_text("False"),
|
||||||
|
plain_text("."),
|
||||||
]),
|
]),
|
||||||
),
|
)
|
||||||
|
}
|
||||||
Reason::IfBranch { index } => {
|
Reason::IfBranch { index } => {
|
||||||
let ith = int_to_ordinal(index);
|
let ith = int_to_ordinal(index);
|
||||||
report_mismatch(
|
report_mismatch(
|
||||||
|
|
|
@ -766,16 +766,16 @@ mod test_reporting {
|
||||||
),
|
),
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
This `if` condition does not evaluate to a boolean value, True or False.
|
This `if` condition should be a Bool, but it isn’t.
|
||||||
|
|
||||||
1 ┆ if "foo" then 2 else 3
|
1 ┆ if "foo" then 2 else 3
|
||||||
┆ ^^^^^
|
┆ ^^^^^
|
||||||
|
|
||||||
It is a string of type:
|
Instead it’s a string of type:
|
||||||
|
|
||||||
Str
|
Str
|
||||||
|
|
||||||
But I need this `if` condition to be a Bool value.
|
`if` conditions must evaluate to a Bool—either `True` or `False`.
|
||||||
|
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue