mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Fix failing reporting tests
This commit is contained in:
parent
101ce7c6e8
commit
633bdd5520
5 changed files with 303 additions and 154 deletions
|
@ -585,20 +585,21 @@ pub fn constrain_expr(
|
|||
branches,
|
||||
..
|
||||
} => {
|
||||
// Infer the condition expression's type.
|
||||
let cond_var = *cond_var;
|
||||
let cond_type = Variable(cond_var);
|
||||
let cond_constraint = constrain_expr(
|
||||
constraints,
|
||||
env,
|
||||
region,
|
||||
&loc_cond.value,
|
||||
NoExpectation(cond_type.clone()),
|
||||
);
|
||||
|
||||
let branch_var = *expr_var;
|
||||
let branch_type = Variable(branch_var);
|
||||
|
||||
let branches_region = {
|
||||
debug_assert!(!branches.is_empty());
|
||||
Region::span_across(
|
||||
&loc_cond.region,
|
||||
// &branches.first().unwrap().region(),
|
||||
&branches.last().unwrap().region(),
|
||||
)
|
||||
};
|
||||
|
||||
let branch_expr_reason =
|
||||
|expected: &Expected<Type>, index, branch_region| match expected {
|
||||
FromAnnotation(name, arity, ann_source, _typ) => {
|
||||
|
@ -654,19 +655,24 @@ pub fn constrain_expr(
|
|||
let pattern_region =
|
||||
Region::across_all(when_branch.patterns.iter().map(|v| &v.region));
|
||||
|
||||
let expected_pattern = |sub_pattern| {
|
||||
PExpected::ForReason(
|
||||
PReason::WhenMatch {
|
||||
index: HumanIndex::zero_based(index),
|
||||
sub_pattern,
|
||||
},
|
||||
cond_type.clone(),
|
||||
pattern_region,
|
||||
)
|
||||
};
|
||||
|
||||
let (new_pattern_vars, new_pattern_headers, pattern_con, branch_con) =
|
||||
constrain_when_branch_help(
|
||||
constraints,
|
||||
env,
|
||||
region,
|
||||
when_branch,
|
||||
PExpected::ForReason(
|
||||
PReason::WhenMatch {
|
||||
index: HumanIndex::zero_based(index),
|
||||
},
|
||||
cond_type.clone(),
|
||||
pattern_region,
|
||||
),
|
||||
expected_pattern,
|
||||
branch_expr_reason(
|
||||
&expected,
|
||||
HumanIndex::zero_based(index),
|
||||
|
@ -698,11 +704,18 @@ pub fn constrain_expr(
|
|||
// the entire when-expression.
|
||||
// branch_cons.extend(pattern_cons);
|
||||
// branch_constraints.push(constraints.and_constraint(pattern_cons));
|
||||
let mut total_cons = Vec::with_capacity(2 * branches.len() + 1);
|
||||
let mut total_cons = Vec::with_capacity(2);
|
||||
|
||||
// After solving the condition variable with what's expected from the branch patterns,
|
||||
// check it against the condition expression.
|
||||
// This is basically exhaustiveness checking, but doesn't check for redundancy.
|
||||
let cond_constraint = constrain_expr(
|
||||
constraints,
|
||||
env,
|
||||
loc_cond.region,
|
||||
&loc_cond.value,
|
||||
Expected::ForReason(Reason::WhenBranches, cond_type, branches_region),
|
||||
);
|
||||
pattern_cons.push(cond_constraint);
|
||||
|
||||
// Solve all the pattern constraints together, introducing variables in the pattern as
|
||||
|
@ -1126,7 +1139,7 @@ fn constrain_when_branch_help(
|
|||
env: &Env,
|
||||
region: Region,
|
||||
when_branch: &WhenBranch,
|
||||
pattern_expected: PExpected<Type>,
|
||||
pattern_expected: impl Fn(HumanIndex) -> PExpected<Type>,
|
||||
expr_expected: Expected<Type>,
|
||||
) -> (
|
||||
Vec<Variable>,
|
||||
|
@ -1151,13 +1164,15 @@ fn constrain_when_branch_help(
|
|||
|
||||
// TODO investigate for error messages, is it better to unify all branches with a variable,
|
||||
// then unify that variable with the expectation?
|
||||
for loc_pattern in &when_branch.patterns {
|
||||
for (i, loc_pattern) in when_branch.patterns.iter().enumerate() {
|
||||
let pattern_expected = pattern_expected(HumanIndex::zero_based(i));
|
||||
|
||||
constrain_pattern(
|
||||
constraints,
|
||||
env,
|
||||
&loc_pattern.value,
|
||||
loc_pattern.region,
|
||||
pattern_expected.clone(),
|
||||
pattern_expected,
|
||||
&mut state,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue