mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Better estimate polarity in exhaustiveness checking
This commit is contained in:
parent
69114cc820
commit
7b9ce492c3
1 changed files with 10 additions and 4 deletions
|
@ -1503,6 +1503,13 @@ fn solve(
|
||||||
expected_type,
|
expected_type,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let cond_source_is_likely_positive_value = category_and_expected.is_ok();
|
||||||
|
let cond_polarity = if cond_source_is_likely_positive_value {
|
||||||
|
Polarity::OF_VALUE
|
||||||
|
} else {
|
||||||
|
Polarity::OF_PATTERN
|
||||||
|
};
|
||||||
|
|
||||||
let real_content = subs.get_content_without_compacting(real_var);
|
let real_content = subs.get_content_without_compacting(real_var);
|
||||||
let branches_content = subs.get_content_without_compacting(branches_var);
|
let branches_content = subs.get_content_without_compacting(branches_var);
|
||||||
let already_have_error = matches!(
|
let already_have_error = matches!(
|
||||||
|
@ -1522,7 +1529,7 @@ fn solve(
|
||||||
branches_var,
|
branches_var,
|
||||||
real_var,
|
real_var,
|
||||||
Mode::EQ,
|
Mode::EQ,
|
||||||
Polarity::OF_PATTERN,
|
cond_polarity,
|
||||||
);
|
);
|
||||||
|
|
||||||
let should_check_exhaustiveness;
|
let should_check_exhaustiveness;
|
||||||
|
@ -1575,7 +1582,7 @@ fn solve(
|
||||||
real_var,
|
real_var,
|
||||||
branches_var,
|
branches_var,
|
||||||
Mode::EQ,
|
Mode::EQ,
|
||||||
Polarity::OF_PATTERN
|
cond_polarity,
|
||||||
),
|
),
|
||||||
Success { .. }
|
Success { .. }
|
||||||
);
|
);
|
||||||
|
@ -1593,7 +1600,7 @@ fn solve(
|
||||||
real_var,
|
real_var,
|
||||||
branches_var,
|
branches_var,
|
||||||
Mode::EQ,
|
Mode::EQ,
|
||||||
Polarity::OF_PATTERN,
|
cond_polarity,
|
||||||
) {
|
) {
|
||||||
Failure(vars, actual_type, expected_type, _bad_impls) => {
|
Failure(vars, actual_type, expected_type, _bad_impls) => {
|
||||||
introduce(subs, rank, pools, &vars);
|
introduce(subs, rank, pools, &vars);
|
||||||
|
@ -1686,7 +1693,6 @@ fn solve(
|
||||||
// `C` was matched as well. Since the positive/negative value determination is
|
// `C` was matched as well. Since the positive/negative value determination is
|
||||||
// only an estimate, we also only apply this heursitic in the "almost equal"
|
// only an estimate, we also only apply this heursitic in the "almost equal"
|
||||||
// case, when there was in fact a unification error.
|
// case, when there was in fact a unification error.
|
||||||
let cond_source_is_likely_positive_value = category_and_expected.is_ok();
|
|
||||||
if cond_source_is_likely_positive_value && has_unification_error {
|
if cond_source_is_likely_positive_value && has_unification_error {
|
||||||
close_pattern_matched_tag_unions(subs, real_var);
|
close_pattern_matched_tag_unions(subs, real_var);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue