mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Include annotation type signatures in Expected
struct
To provide better error messages and suggestions related to changing type annotations, we now pass annotation type signatures all the way down through the constraint solver. At constraint generation we associate the type signature with a unique variable, and during error reporting, we pull out an `ErrorType` corresponding to the original type signature, by looking up the unique variable. This gives us two nice things: 1. It means we don't have to pass the original, AST-like type annotation, which can be quite large, to everyone who looks at an expectation. 2. It gives us a translation from a `Type` to an `ErrorType` for free using the existing translation procedure in `roc_types::subs`, without having to create a new translation function.
This commit is contained in:
parent
8726e38dad
commit
ee34e79790
11 changed files with 152 additions and 42 deletions
|
@ -82,6 +82,16 @@ type Outcome = Vec<Mismatch>;
|
|||
|
||||
#[inline(always)]
|
||||
pub fn unify(subs: &mut Subs, var1: Variable, var2: Variable) -> Unified {
|
||||
unify_help(subs, var1, var2, true)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn unify_without_error_compaction(subs: &mut Subs, var1: Variable, var2: Variable) -> Unified {
|
||||
unify_help(subs, var1, var2, false)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn unify_help(subs: &mut Subs, var1: Variable, var2: Variable, compact_errors: bool) -> Unified {
|
||||
let mut vars = Vec::new();
|
||||
let mismatches = unify_pool(subs, &mut vars, var1, var2);
|
||||
|
||||
|
@ -93,7 +103,9 @@ pub fn unify(subs: &mut Subs, var1: Variable, var2: Variable) -> Unified {
|
|||
|
||||
problems.extend(problems2);
|
||||
|
||||
subs.union(var1, var2, Content::Error.into());
|
||||
if compact_errors {
|
||||
subs.union(var1, var2, Content::Error.into());
|
||||
}
|
||||
|
||||
if !problems.is_empty() {
|
||||
Unified::BadType(vars, problems.remove(0))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue