Merge pull request #4082 from roc-lang/update-cli-platform-unreachables

Support unification with uninhabited tag variants in more places
This commit is contained in:
Folkert de Vries 2022-09-21 12:18:38 +02:00 committed by GitHub
commit cc202a4cf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 64 deletions

View file

@ -1356,16 +1356,8 @@ fn solve(
);
let snapshot = subs.snapshot();
let unify_cond_and_patterns_outcome = {
// When unifying the cond type with what the branches expect, allow the
// branches to gain constructors that are uninabited; that way, we can permit
// unification of things like
// [Ok Str] ~ [Ok Str, Result []]
// which we want here, because `Result []` need not be matched - it is
// impossible to construct!
let mode = Mode::EQ_WITH_EXTENSION_BY_UNINHABITED_TYPES;
unify(&mut UEnv::new(subs), branches_var, real_var, mode)
};
let unify_cond_and_patterns_outcome =
unify(&mut UEnv::new(subs), branches_var, real_var, Mode::EQ);
let should_check_exhaustiveness;
match unify_cond_and_patterns_outcome {

View file

@ -7791,4 +7791,36 @@ mod solve_expr {
"Str",
);
}
#[test]
fn match_on_result_with_uninhabited_error_destructuring() {
infer_eq_without_problem(
indoc!(
r#"
x : Result Str []
x = Ok "abc"
Ok str = x
str
"#
),
"Str",
);
}
#[test]
fn match_on_result_with_uninhabited_error_destructuring_in_lambda_syntax() {
infer_eq_without_problem(
indoc!(
r#"
x : Result Str [] -> Str
x = \Ok s -> s
x
"#
),
"Result Str [] -> Str",
);
}
}