From ef77ff35cf48b98244c83ef3c398a38fff9bb8cb Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 5 May 2022 21:14:54 -0400 Subject: [PATCH] Improve expectation for platform requires mismatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` ── TYPE MISMATCH ───── examples/hello-world/rust-platform/./Package-Config.roc ─ Something is off with the type annotation of the main required symbol: 2│ requires {} { main : a -> a } ^^^^^^ This #UserApp.main value is a: Str But the type annotation on main says it should be: a -> a ──────────────────────────────────────────────────────────────────────────────── ``` --- compiler/constrain/src/module.rs | 2 +- compiler/types/src/types.rs | 4 ++++ reporting/src/error/type.rs | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/constrain/src/module.rs b/compiler/constrain/src/module.rs index 60700cbe35..0051a7049e 100644 --- a/compiler/constrain/src/module.rs +++ b/compiler/constrain/src/module.rs @@ -155,7 +155,7 @@ fn constrain_symbols_from_requires( Expected::FromAnnotation( loc_symbol.map(|&s| Pattern::Identifier(s)), arity, - AnnotationSource::TypedBody { + AnnotationSource::RequiredSymbol { region: loc_type.region, }, loc_type.value, diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 95a7d61029..21370aee47 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -1708,6 +1708,9 @@ pub enum AnnotationSource { TypedBody { region: Region, }, + RequiredSymbol { + region: Region, + }, } impl AnnotationSource { @@ -1716,6 +1719,7 @@ impl AnnotationSource { &Self::TypedIfBranch { region, .. } | &Self::TypedWhenBranch { region, .. } | &Self::TypedBody { region, .. } => region, + &Self::RequiredSymbol { region, .. } => region, } } } diff --git a/reporting/src/error/type.rs b/reporting/src/error/type.rs index 9fbdd6eb2e..a2000ad162 100644 --- a/reporting/src/error/type.rs +++ b/reporting/src/error/type.rs @@ -540,12 +540,18 @@ fn to_expr_report<'b>( the_name_text, alloc.text(" definition:"), ]), + RequiredSymbol { .. } => alloc.concat([ + alloc.text("type annotation of "), + the_name_text, + alloc.text(" required symbol:"), + ]), }; let it_is = match annotation_source { TypedIfBranch { index, .. } => format!("The {} branch is", index.ordinal()), TypedWhenBranch { index, .. } => format!("The {} branch is", index.ordinal()), TypedBody { .. } => "The body is".into(), + RequiredSymbol { .. } => "The provided type is".into(), }; let expectation_context = ExpectationContext::Annotation {