mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
exhaustiveness for record guards
This commit is contained in:
parent
0985037754
commit
82655556ab
4 changed files with 165 additions and 52 deletions
|
@ -943,7 +943,7 @@ fn store_record_destruct<'a>(
|
|||
stored.push((*symbol, destruct.layout.clone(), load));
|
||||
}
|
||||
Pattern::Underscore => {
|
||||
// important that this is special-cased: mono record patterns will extract all the
|
||||
// important that this is special-cased to do nothing: mono record patterns will extract all the
|
||||
// fields, but those not bound in the source code are guarded with the underscore
|
||||
// pattern. So given some record `{ x : a, y : b }`, a match
|
||||
//
|
||||
|
@ -993,6 +993,15 @@ fn from_can_when<'a>(
|
|||
|
||||
let mono_pattern = from_can_pattern(env, &loc_when_pattern.value);
|
||||
|
||||
// record pattern matches can have 1 branch and typecheck, but may still not be exhaustive
|
||||
match crate::pattern::check(
|
||||
Region::zero(),
|
||||
&[Located::at(loc_when_pattern.region, mono_pattern.clone())],
|
||||
) {
|
||||
Ok(_) => {}
|
||||
Err(errors) => panic!("Errors in patterns: {:?}", errors),
|
||||
}
|
||||
|
||||
let cond_layout = Layout::from_var(env.arena, cond_var, env.subs, env.pointer_size)
|
||||
.unwrap_or_else(|err| panic!("TODO turn this into a RuntimeError {:?}", err));
|
||||
let cond_symbol = env.fresh_symbol();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue