mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Merge pull request #1093 from rtfeldman/type-identifier-messages
Type identifier messages
This commit is contained in:
commit
e1c70fddec
4 changed files with 131 additions and 52 deletions
|
@ -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(
|
pub fn canonicalize_annotation(
|
||||||
env: &mut Env,
|
env: &mut Env,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
|
@ -446,7 +453,16 @@ fn can_annotation_help(
|
||||||
local_aliases,
|
local_aliases,
|
||||||
references,
|
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();
|
let var = var_store.fresh();
|
||||||
|
|
||||||
introduced_variables.insert_wildcard(var);
|
introduced_variables.insert_wildcard(var);
|
||||||
|
@ -542,8 +558,9 @@ fn can_assigned_fields<'a>(
|
||||||
field = nested;
|
field = nested;
|
||||||
continue 'inner;
|
continue 'inner;
|
||||||
}
|
}
|
||||||
Malformed(_) => {
|
Malformed(string) => {
|
||||||
// TODO report this?
|
malformed(env, region, string);
|
||||||
|
|
||||||
// completely skip this element, advance to the next tag
|
// completely skip this element, advance to the next tag
|
||||||
continue 'outer;
|
continue 'outer;
|
||||||
}
|
}
|
||||||
|
@ -645,8 +662,9 @@ fn can_tags<'a>(
|
||||||
tag = nested;
|
tag = nested;
|
||||||
continue 'inner;
|
continue 'inner;
|
||||||
}
|
}
|
||||||
Tag::Malformed(_) => {
|
Tag::Malformed(string) => {
|
||||||
// TODO report this?
|
malformed(env, region, string);
|
||||||
|
|
||||||
// completely skip this element, advance to the next tag
|
// completely skip this element, advance to the next tag
|
||||||
continue 'outer;
|
continue 'outer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,7 @@ pub enum RuntimeError {
|
||||||
},
|
},
|
||||||
InvalidPrecedence(PrecedenceProblem, Region),
|
InvalidPrecedence(PrecedenceProblem, Region),
|
||||||
MalformedIdentifier(Box<str>, roc_parse::ident::BadIdent, Region),
|
MalformedIdentifier(Box<str>, roc_parse::ident::BadIdent, Region),
|
||||||
|
MalformedTypeName(Box<str>, Region),
|
||||||
MalformedClosure(Region),
|
MalformedClosure(Region),
|
||||||
InvalidRecordUpdate {
|
InvalidRecordUpdate {
|
||||||
region: Region,
|
region: Region,
|
||||||
|
|
|
@ -776,8 +776,20 @@ fn pretty_runtime_error<'b>(
|
||||||
}
|
}
|
||||||
RuntimeError::MalformedIdentifier(_box_str, bad_ident, surroundings) => {
|
RuntimeError::MalformedIdentifier(_box_str, bad_ident, surroundings) => {
|
||||||
to_bad_ident_expr_report(alloc, 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::MalformedClosure(_) => todo!(""),
|
||||||
RuntimeError::InvalidFloat(sign @ FloatErrorKind::PositiveInfinity, region, _raw_str)
|
RuntimeError::InvalidFloat(sign @ FloatErrorKind::PositiveInfinity, region, _raw_str)
|
||||||
|
|
|
@ -4474,16 +4474,16 @@ mod test_reporting {
|
||||||
report_problem_as(
|
report_problem_as(
|
||||||
"# comment with a \t\n4",
|
"# comment with a \t\n4",
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
"
|
||||||
── TAB CHARACTER ───────────────────────────────────────────────────────────────
|
── TAB CHARACTER ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
I encountered a tab character
|
I encountered a tab character
|
||||||
|
|
||||||
1│ # comment with a
|
1│ # comment with a \t
|
||||||
^
|
^
|
||||||
|
|
||||||
Tab characters are not allowed.
|
Tab characters are not allowed.
|
||||||
"#
|
"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -4545,7 +4545,19 @@ mod test_reporting {
|
||||||
f
|
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 ──────────────────────────────────────────────────────────────────
|
// ── DOUBLE DOT ──────────────────────────────────────────────────────────────────
|
||||||
|
@ -4568,7 +4580,19 @@ mod test_reporting {
|
||||||
f
|
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 ────────────────────────────────────────────────────────────────
|
// ── TRAILING DOT ────────────────────────────────────────────────────────────────
|
||||||
|
@ -4619,7 +4643,19 @@ mod test_reporting {
|
||||||
f
|
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 ────────────────────────────────────────────────────────
|
// ── WEIRD QUALIFIED NAME ────────────────────────────────────────────────────────
|
||||||
|
@ -4643,7 +4679,19 @@ mod test_reporting {
|
||||||
f
|
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.
|
||||||
|
"#
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue