From 822e38d0260f8738195dbe833be275f499b5051a Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Wed, 23 Feb 2022 22:07:52 -0500 Subject: [PATCH] Fix opaque reporting tests --- compiler/can/src/expr.rs | 4 ++-- reporting/src/error/canonicalize.rs | 6 ++++-- reporting/tests/test_reporting.rs | 23 ++++++++++++----------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 2c319d1f5c..9639af9ca9 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -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()); diff --git a/reporting/src/error/canonicalize.rs b/reporting/src/error/canonicalize.rs index 6d12751660..1091a80b79 100644 --- a/reporting/src/error/canonicalize.rs +++ b/reporting/src/error/canonicalize.rs @@ -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; } } diff --git a/reporting/tests/test_reporting.rs b/reporting/tests/test_reporting.rs index c16690ec0d..b6448dc7fb 100644 --- a/reporting/tests/test_reporting.rs +++ b/reporting/tests/test_reporting.rs @@ -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! "# ), )