Improve expectation for platform requires mismatch

```
── 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

────────────────────────────────────────────────────────────────────────────────
```
This commit is contained in:
ayazhafiz 2022-05-05 21:14:54 -04:00 committed by Richard Feldman
parent 514af619f5
commit ef77ff35cf
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
3 changed files with 11 additions and 1 deletions

View file

@ -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,

View file

@ -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,
}
}
}

View file

@ -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 {