report a Foo.Bar malformed identifier

This commit is contained in:
Folkert 2020-11-12 20:48:34 +01:00
parent 10255a90b1
commit c05ec12be0
3 changed files with 35 additions and 6 deletions

View file

@ -725,10 +725,11 @@ pub fn canonicalize_expr<'a>(
}
ast::Expr::MalformedIdent(name) => {
use roc_problem::can::RuntimeError::*;
(
RuntimeError(MalformedIdentifier((*name).into(), region)),
Output::default(),
)
let problem = MalformedIdentifier((*name).into(), region);
env.problem(Problem::RuntimeError(problem.clone()));
(RuntimeError(problem), Output::default())
}
ast::Expr::Nested(sub_expr) => {
let (answer, output) = canonicalize_expr(env, var_store, scope, region, sub_expr);

View file

@ -427,8 +427,15 @@ fn pretty_runtime_error<'b>(
// do nothing, reported with PrecedenceProblem
unreachable!()
}
RuntimeError::MalformedIdentifier(_, _) => {
todo!("malformed identifier, currently gives a parse error and thus is unreachable")
RuntimeError::MalformedIdentifier(box_str, region) => {
alloc.stack(vec![
alloc.concat(vec![
alloc.reflow("The ")
.append(format!("`{}`", box_str))
.append(alloc.reflow(" identifier is malformed:")),
]),
alloc.region(region),
])
}
RuntimeError::MalformedClosure(_) => todo!(""),
RuntimeError::InvalidFloat(sign @ FloatErrorKind::PositiveInfinity, region, _raw_str)

View file

@ -3930,4 +3930,25 @@ mod test_reporting {
),
)
}
#[test]
fn qualified_global_tag() {
report_problem_as(
indoc!(
r#"
Foo.Bar
"#
),
indoc!(
r#"
SYNTAX PROBLEM
The `Foo.Bar` identifier is malformed:
1 Foo.Bar
^^^^^^^
"#
),
)
}
}