From 7b9ce492c34d288707811b98139f07a71b829653 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 25 Oct 2022 17:19:01 -0500 Subject: [PATCH] Better estimate polarity in exhaustiveness checking --- crates/compiler/solve/src/solve.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/compiler/solve/src/solve.rs b/crates/compiler/solve/src/solve.rs index e75ab52840..d03ac860ef 100644 --- a/crates/compiler/solve/src/solve.rs +++ b/crates/compiler/solve/src/solve.rs @@ -1503,6 +1503,13 @@ fn solve( 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 branches_content = subs.get_content_without_compacting(branches_var); let already_have_error = matches!( @@ -1522,7 +1529,7 @@ fn solve( branches_var, real_var, Mode::EQ, - Polarity::OF_PATTERN, + cond_polarity, ); let should_check_exhaustiveness; @@ -1575,7 +1582,7 @@ fn solve( real_var, branches_var, Mode::EQ, - Polarity::OF_PATTERN + cond_polarity, ), Success { .. } ); @@ -1593,7 +1600,7 @@ fn solve( real_var, branches_var, Mode::EQ, - Polarity::OF_PATTERN, + cond_polarity, ) { Failure(vars, actual_type, expected_type, _bad_impls) => { introduce(subs, rank, pools, &vars); @@ -1686,7 +1693,6 @@ fn solve( // `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" // 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 { close_pattern_matched_tag_unions(subs, real_var); }