Fix opaque reporting tests

This commit is contained in:
ayazhafiz 2022-02-23 22:07:52 -05:00
parent ccd4963e0f
commit 822e38d026
3 changed files with 18 additions and 15 deletions

View file

@ -429,12 +429,12 @@ pub fn canonicalize_expr<'a>(
let problem =
roc_problem::can::RuntimeError::OpaqueAppliedToMultipleArgs(region);
env.problem(Problem::RuntimeError(problem.clone()));
(RuntimeError(problem), Output::default())
(RuntimeError(problem), output)
} else {
match scope.lookup_opaque_ref(name, loc_fn.region) {
Err(runtime_error) => {
env.problem(Problem::RuntimeError(runtime_error.clone()));
(RuntimeError(runtime_error), Output::default())
(RuntimeError(runtime_error), output)
}
Ok((name, opaque_def)) => {
let argument = Box::new(args.pop().unwrap());

View file

@ -31,6 +31,8 @@ const NUMBER_OVERFLOWS_SUFFIX: &str = "NUMBER OVERFLOWS SUFFIX";
const NUMBER_UNDERFLOWS_SUFFIX: &str = "NUMBER UNDERFLOWS SUFFIX";
const OPAQUE_NOT_DEFINED: &str = "OPAQUE NOT DEFINED";
const OPAQUE_DECLARED_OUTSIDE_SCOPE: &str = "OPAQUE DECLARED OUTSIDE SCOPE";
const OPAQUE_NOT_APPLIED: &str = "OPAQUE NOT APPLIED";
const OPAQUE_OVER_APPLIED: &str = "OPAQUE APPLIED TO TOO MANY ARGS";
pub fn can_problem<'b>(
alloc: &'b RocDocAllocator<'b>,
@ -1454,7 +1456,7 @@ fn pretty_runtime_error<'b>(
alloc.note("Opaque types always wrap exactly one argument!"),
]);
title = OPAQUE_DECLARED_OUTSIDE_SCOPE;
title = OPAQUE_NOT_APPLIED;
}
RuntimeError::OpaqueAppliedToMultipleArgs(region) => {
doc = alloc.stack(vec![
@ -1463,7 +1465,7 @@ fn pretty_runtime_error<'b>(
alloc.note("Opaque types always wrap exactly one argument!"),
]);
title = OPAQUE_DECLARED_OUTSIDE_SCOPE;
title = OPAQUE_OVER_APPLIED;
}
}

View file

@ -8208,10 +8208,20 @@ I need all branches in an `if` to have the same type!
OtherModule.$Age 21
"#
),
// TODO: get rid of the second error. Consider parsing OtherModule.$Age to completion
// and checking it during can.
// TODO: get rid of the first error. Consider parsing OtherModule.$Age to completion
// and checking it during can. The reason the error appears is because it is parsed as
// Apply(Error(OtherModule), [ $Age, 21 ])
indoc!(
r#"
OPAQUE NOT APPLIED
This opaque is not applied to an argument:
1 OtherModule.$Age 21
^^^^
Note: Opaque types always wrap exactly one argument!
SYNTAX PROBLEM
I am trying to parse a qualified name here:
@ -8221,15 +8231,6 @@ I need all branches in an `if` to have the same type!
I was expecting to see an identifier next, like height. A complete
qualified name looks something like Json.Decode.string.
OPAQUE NOT DEFINED
The opaque type Age referenced here is not defined:
1 OtherModule.$Age 21
^^^^
Note: It looks like there are no opaque types declared in this scope yet!
"#
),
)