mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +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)
|
||||||
|
|
|
@ -3265,20 +3265,20 @@ mod test_reporting {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
── TYPE MISMATCH ───────────────────────────────────────────────────────────────
|
── TYPE MISMATCH ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
Something is off with the body of the `x` definition:
|
Something is off with the body of the `x` definition:
|
||||||
|
|
||||||
4│ x : AList I64 I64
|
4│ x : AList I64 I64
|
||||||
5│ x = ACons 0 (BCons 1 (ACons "foo" BNil ))
|
5│ x = ACons 0 (BCons 1 (ACons "foo" BNil ))
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
This `ACons` global tag application has the type:
|
This `ACons` global tag application has the type:
|
||||||
|
|
||||||
[ ACons Num (Integer Signed64) [ BCons (Num a) [ ACons Str [ BNil
|
[ ACons Num (Integer Signed64) [ BCons (Num a) [ ACons Str [ BNil
|
||||||
]b ]c ]d, ANil ]
|
]b ]c ]d, ANil ]
|
||||||
|
|
||||||
But the type annotation on `x` says it should be:
|
But the type annotation on `x` says it should be:
|
||||||
|
|
||||||
[ ACons I64 BList I64 I64, ANil ]
|
[ ACons I64 BList I64 I64, ANil ]
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
|
@ -4155,12 +4155,12 @@ mod test_reporting {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
── UNKNOWN OPERATOR ────────────────────────────────────────────────────────────
|
── UNKNOWN OPERATOR ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
This looks like an operator, but it's not one I recognize!
|
This looks like an operator, but it's not one I recognize!
|
||||||
|
|
||||||
1│ f :: I64
|
1│ f :: I64
|
||||||
^^
|
^^
|
||||||
|
|
||||||
I have no specific suggestion for this operator, see TODO for the full
|
I have no specific suggestion for this operator, see TODO for the full
|
||||||
list of operators in Roc.
|
list of operators in Roc.
|
||||||
"#
|
"#
|
||||||
|
@ -4188,12 +4188,12 @@ mod test_reporting {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
── TOO MANY ARGS ───────────────────────────────────────────────────────────────
|
── TOO MANY ARGS ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
This value is not a function, but it was given 3 arguments:
|
This value is not a function, but it was given 3 arguments:
|
||||||
|
|
||||||
3│ x == 5
|
3│ x == 5
|
||||||
^
|
^
|
||||||
|
|
||||||
Are there any missing commas? Or missing parentheses?
|
Are there any missing commas? Or missing parentheses?
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
|
@ -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.
|
||||||
"#
|
"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -4500,9 +4500,9 @@ mod test_reporting {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
── BAD TYPE VARIABLE ───────────────────────────────────────────────────────────
|
── BAD TYPE VARIABLE ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
I am expecting a type variable, but I got stuck here:
|
I am expecting a type variable, but I got stuck here:
|
||||||
|
|
||||||
1│ f : (
|
1│ f : (
|
||||||
^
|
^
|
||||||
"#
|
"#
|
||||||
|
@ -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.
|
||||||
|
"#
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4658,19 +4706,19 @@ mod test_reporting {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
── MISSING FINAL EXPRESSION ────────────────────────────────────────────────────
|
── MISSING FINAL EXPRESSION ────────────────────────────────────────────────────
|
||||||
|
|
||||||
I am partway through parsing a definition's final expression, but I
|
I am partway through parsing a definition's final expression, but I
|
||||||
got stuck here:
|
got stuck here:
|
||||||
|
|
||||||
1│ f : Foo.foo
|
1│ f : Foo.foo
|
||||||
^
|
^
|
||||||
|
|
||||||
This definition is missing a final expression. A nested definition
|
This definition is missing a final expression. A nested definition
|
||||||
must be followed by either another definition, or an expression
|
must be followed by either another definition, or an expression
|
||||||
|
|
||||||
x = 4
|
x = 4
|
||||||
y = 2
|
y = 2
|
||||||
|
|
||||||
x + y
|
x + y
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
|
@ -4973,13 +5021,13 @@ mod test_reporting {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
── MISSING EXPRESSION ──────────────────────────────────────────────────────────
|
── MISSING EXPRESSION ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
I am partway through parsing a definition, but I got stuck here:
|
I am partway through parsing a definition, but I got stuck here:
|
||||||
|
|
||||||
1│ when Just 4 is
|
1│ when Just 4 is
|
||||||
2│ Just when ->
|
2│ Just when ->
|
||||||
^
|
^
|
||||||
|
|
||||||
I was expecting to see an expression like 42 or "hello".
|
I was expecting to see an expression like 42 or "hello".
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
|
@ -5646,14 +5694,14 @@ mod test_reporting {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
── SYNTAX PROBLEM ──────────────────────────────────────────────────────────────
|
── SYNTAX PROBLEM ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
I cannot find a `bar` value
|
I cannot find a `bar` value
|
||||||
|
|
||||||
1│ [ "foo", bar("") ]
|
1│ [ "foo", bar("") ]
|
||||||
^^^
|
^^^
|
||||||
|
|
||||||
these names seem close though:
|
these names seem close though:
|
||||||
|
|
||||||
Nat
|
Nat
|
||||||
Str
|
Str
|
||||||
U8
|
U8
|
||||||
|
@ -5729,16 +5777,16 @@ mod test_reporting {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
── UNKNOWN OPERATOR ────────────────────────────────────────────────────────────
|
── UNKNOWN OPERATOR ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
This looks like an operator, but it's not one I recognize!
|
This looks like an operator, but it's not one I recognize!
|
||||||
|
|
||||||
1│ main =
|
1│ main =
|
||||||
2│ (\x -> x) : I64
|
2│ (\x -> x) : I64
|
||||||
^
|
^
|
||||||
|
|
||||||
The has-type operator : can only occur in a definition's type
|
The has-type operator : can only occur in a definition's type
|
||||||
signature, like
|
signature, like
|
||||||
|
|
||||||
increment : I64 -> I64
|
increment : I64 -> I64
|
||||||
increment = \x -> x + 1
|
increment = \x -> x + 1
|
||||||
"#
|
"#
|
||||||
|
@ -5759,19 +5807,19 @@ mod test_reporting {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
── MISSING FINAL EXPRESSION ────────────────────────────────────────────────────
|
── MISSING FINAL EXPRESSION ────────────────────────────────────────────────────
|
||||||
|
|
||||||
I am partway through parsing a definition's final expression, but I
|
I am partway through parsing a definition's final expression, but I
|
||||||
got stuck here:
|
got stuck here:
|
||||||
|
|
||||||
1│ main = 5 -> 3
|
1│ main = 5 -> 3
|
||||||
^
|
^
|
||||||
|
|
||||||
This definition is missing a final expression. A nested definition
|
This definition is missing a final expression. A nested definition
|
||||||
must be followed by either another definition, or an expression
|
must be followed by either another definition, or an expression
|
||||||
|
|
||||||
x = 4
|
x = 4
|
||||||
y = 2
|
y = 2
|
||||||
|
|
||||||
x + y
|
x + y
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue