Merge pull request #1093 from rtfeldman/type-identifier-messages

Type identifier messages
This commit is contained in:
Richard Feldman 2021-03-21 19:20:18 -04:00 committed by GitHub
commit e1c70fddec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 131 additions and 52 deletions

View file

@ -65,6 +65,13 @@ impl IntroducedVariables {
}
}
fn malformed(env: &mut Env, region: Region, name: &str) {
use roc_problem::can::RuntimeError::*;
let problem = MalformedTypeName((*name).into(), region);
env.problem(roc_problem::can::Problem::RuntimeError(problem));
}
pub fn canonicalize_annotation(
env: &mut Env,
scope: &mut Scope,
@ -446,7 +453,16 @@ fn can_annotation_help(
local_aliases,
references,
),
Wildcard | Malformed(_) => {
Wildcard => {
let var = var_store.fresh();
introduced_variables.insert_wildcard(var);
Type::Variable(var)
}
Malformed(string) => {
malformed(env, region, string);
let var = var_store.fresh();
introduced_variables.insert_wildcard(var);
@ -542,8 +558,9 @@ fn can_assigned_fields<'a>(
field = nested;
continue 'inner;
}
Malformed(_) => {
// TODO report this?
Malformed(string) => {
malformed(env, region, string);
// completely skip this element, advance to the next tag
continue 'outer;
}
@ -645,8 +662,9 @@ fn can_tags<'a>(
tag = nested;
continue 'inner;
}
Tag::Malformed(_) => {
// TODO report this?
Tag::Malformed(string) => {
malformed(env, region, string);
// completely skip this element, advance to the next tag
continue 'outer;
}

View file

@ -134,6 +134,7 @@ pub enum RuntimeError {
},
InvalidPrecedence(PrecedenceProblem, Region),
MalformedIdentifier(Box<str>, roc_parse::ident::BadIdent, Region),
MalformedTypeName(Box<str>, Region),
MalformedClosure(Region),
InvalidRecordUpdate {
region: Region,

View file

@ -776,8 +776,20 @@ fn pretty_runtime_error<'b>(
}
RuntimeError::MalformedIdentifier(_box_str, bad_ident, surroundings) => {
to_bad_ident_expr_report(alloc, bad_ident, surroundings)
}
RuntimeError::MalformedTypeName(_box_str, surroundings) => {
alloc.stack(vec![
alloc.reflow(r"I am confused by this type name:"),
alloc.region(surroundings),
alloc.concat(vec![
alloc.reflow("Type names start with an uppercase letter, "),
alloc.reflow("and can optionally be qualified by a module name, like "),
alloc.parser_suggestion("Bool"),
alloc.reflow(" or "),
alloc.parser_suggestion("Http.Request.Request"),
alloc.reflow("."),
]),
])
}
RuntimeError::MalformedClosure(_) => todo!(""),
RuntimeError::InvalidFloat(sign @ FloatErrorKind::PositiveInfinity, region, _raw_str)

View file

@ -4474,16 +4474,16 @@ mod test_reporting {
report_problem_as(
"# comment with a \t\n4",
indoc!(
r#"
"
TAB CHARACTER
I encountered a tab character
1 # comment with a
1 # comment with a \t
^
Tab characters are not allowed.
"#
"
),
)
}
@ -4545,7 +4545,19 @@ mod test_reporting {
f
"#
),
indoc!(r#""#),
indoc!(
r#"
SYNTAX PROBLEM
I am confused by this type name:
1 f : Foo..Bar
^^^^^^^^
Type names start with an uppercase letter, and can optionally be
qualified by a module name, like Bool or Http.Request.Request.
"#
),
)
// ── DOUBLE DOT ──────────────────────────────────────────────────────────────────
@ -4568,7 +4580,19 @@ mod test_reporting {
f
"#
),
indoc!(r#""#),
indoc!(
r#"
SYNTAX PROBLEM
I am confused by this type name:
1 f : Foo.Bar.
^^^^^^^^
Type names start with an uppercase letter, and can optionally be
qualified by a module name, like Bool or Http.Request.Request.
"#
),
)
// ── TRAILING DOT ────────────────────────────────────────────────────────────────
@ -4619,7 +4643,19 @@ mod test_reporting {
f
"#
),
indoc!(r#""#),
indoc!(
r#"
SYNTAX PROBLEM
I am confused by this type name:
1 f : Foo.1
^^^^^
Type names start with an uppercase letter, and can optionally be
qualified by a module name, like Bool or Http.Request.Request.
"#
),
)
// ── WEIRD QUALIFIED NAME ────────────────────────────────────────────────────────
@ -4643,7 +4679,19 @@ mod test_reporting {
f
"#
),
indoc!(r#""#),
indoc!(
r#"
SYNTAX PROBLEM
I am confused by this type name:
1 f : Foo.foo
^^^^^^^
Type names start with an uppercase letter, and can optionally be
qualified by a module name, like Bool or Http.Request.Request.
"#
),
)
}