fix: list items in when were not being added to scope

fix: tuple clause must preserve previous clause properties state
This commit is contained in:
microproofs 2023-06-02 18:24:44 -04:00 committed by Kasey
parent 8f0cf289b4
commit cdf8bd6548
1 changed files with 19 additions and 28 deletions

View File

@ -825,6 +825,8 @@ impl<'a> CodeGenerator<'a> {
clause_then_stack = clause_guard_stack; clause_then_stack = clause_guard_stack;
} }
let prev_clause_properties = clause_properties.clone();
// deal with clause pattern and then itself // deal with clause pattern and then itself
self.when_pattern( self.when_pattern(
&clause.pattern, &clause.pattern,
@ -950,18 +952,14 @@ impl<'a> CodeGenerator<'a> {
defined_tuple_indices, defined_tuple_indices,
.. ..
} => { } => {
let prev_defined_tuple_indices = defined_tuple_indices.clone(); let ClauseProperties::TupleClause { defined_tuple_indices: prev_defined_tuple_indices, .. } = prev_clause_properties
let subject_name = original_subject_name.clone(); else {
unreachable!()
let current_defined_tuple_indices = match clause_properties {
ClauseProperties::TupleClause {
defined_tuple_indices,
..
} => defined_tuple_indices.clone(),
_ => unreachable!(),
}; };
let indices_to_define = current_defined_tuple_indices let subject_name = original_subject_name.clone();
let indices_to_define = defined_tuple_indices
.difference(&prev_defined_tuple_indices) .difference(&prev_defined_tuple_indices)
.cloned() .cloned()
.collect(); .collect();
@ -1196,32 +1194,25 @@ impl<'a> CodeGenerator<'a> {
}) })
.collect_vec(); .collect_vec();
if tail.is_some() && !tail_head_names.is_empty() { let tail_var = if elements.len() == 1 || elements.is_empty() {
let tail_var = if elements.len() == 1 {
clause_properties.original_subject_name().clone() clause_properties.original_subject_name().clone()
} else { } else {
format!("__tail_{}", elements.len() - 2) format!("__tail_{}", elements.len() - 2)
}; };
let tail = if &tail_name == "_" { let tail = if &tail_name == "_" || tail_name.is_empty() {
None None
} else { } else {
Some((tail_var, tail_name)) Some((tail_var, tail_name))
}; };
if tail.is_some() || !tail_head_names.is_empty() {
pattern_stack.list_expose( pattern_stack.list_expose(
tipo.clone().into(), tipo.clone().into(),
tail_head_names, tail_head_names,
tail, tail,
nested_pattern, nested_pattern,
); );
} else if !tail_head_names.is_empty() {
pattern_stack.list_expose(
tipo.clone().into(),
tail_head_names,
None,
nested_pattern,
);
} }
pattern_stack.merge_child(value_stack); pattern_stack.merge_child(value_stack);