mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
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:
commit
cc202a4cf9
4 changed files with 81 additions and 64 deletions
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue