fix: fixed how the ir was generating for expect Void, expect Bool, let Void
add some acceptance tests for the various scenarios
This commit is contained in:
parent
280284d4a1
commit
fc1b8738df
|
@ -1929,7 +1929,9 @@ impl<'a> CodeGenerator<'a> {
|
|||
.collect_vec();
|
||||
|
||||
pattern_stack.fields_expose(indices, false, expect_stack);
|
||||
} else if tipo.is_bool() || tipo.is_void() {
|
||||
} else if (tipo.is_bool() || tipo.is_void())
|
||||
&& assignment_properties.kind.is_expect()
|
||||
{
|
||||
pattern_stack.merge_child(expect_stack);
|
||||
} else {
|
||||
pattern_stack.let_assignment("_", expect_stack);
|
||||
|
@ -2086,8 +2088,15 @@ impl<'a> CodeGenerator<'a> {
|
|||
tipo,
|
||||
..
|
||||
} => {
|
||||
if tipo.is_bool() {
|
||||
let PatternConstructor::Record { name, .. } = constructor;
|
||||
|
||||
expect_stack.expect_bool(name == "True", value_stack);
|
||||
} else if tipo.is_void() {
|
||||
expect_stack.choose_unit(value_stack);
|
||||
} else {
|
||||
let field_map = match constructor {
|
||||
PatternConstructor::Record { field_map, .. } => field_map.clone().unwrap(),
|
||||
PatternConstructor::Record { field_map, .. } => field_map,
|
||||
};
|
||||
|
||||
let data_type =
|
||||
|
@ -2115,8 +2124,10 @@ impl<'a> CodeGenerator<'a> {
|
|||
.iter()
|
||||
.filter_map(|item| {
|
||||
let label = item.label.clone().unwrap_or_default();
|
||||
let field_map = field_map.as_ref().unwrap_or_else(|| unreachable!());
|
||||
|
||||
let field_index = field_map.fields.get(&label).map(|x| &x.0).unwrap_or(&0);
|
||||
let field_index =
|
||||
field_map.fields.get(&label).map(|x| &x.0).unwrap_or(&0);
|
||||
|
||||
let mut inner_stack = expect_stack.empty_with_scope();
|
||||
|
||||
|
@ -2183,6 +2194,7 @@ impl<'a> CodeGenerator<'a> {
|
|||
|
||||
expect_stack.merge_child(stacks);
|
||||
}
|
||||
}
|
||||
Pattern::Tuple { elems, .. } => {
|
||||
let mut type_map: IndexMap<usize, Arc<Type>> = IndexMap::new();
|
||||
|
||||
|
@ -4157,7 +4169,8 @@ impl<'a> CodeGenerator<'a> {
|
|||
arg_stack.push(term);
|
||||
return;
|
||||
} else if tipo.is_void() {
|
||||
arg_stack.push(Term::bool(true));
|
||||
let term = left.choose_unit(right.choose_unit(Term::bool(true)));
|
||||
arg_stack.push(term);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,3 +9,15 @@ test expect_false() {
|
|||
expect False = val < 0
|
||||
True
|
||||
}
|
||||
|
||||
test expect_data_false() {
|
||||
let val: Data = 0 > 5
|
||||
expect False: Bool = val
|
||||
True
|
||||
}
|
||||
|
||||
test expect_data_true() {
|
||||
let val: Data = 0 < 5
|
||||
expect True: Bool = val
|
||||
True
|
||||
}
|
||||
|
|
|
@ -1,9 +1,32 @@
|
|||
test foo() {
|
||||
let bar =
|
||||
Void
|
||||
test foo1() {
|
||||
let bar: Data = Void
|
||||
|
||||
expect Void =
|
||||
bar
|
||||
let x = True
|
||||
|
||||
True
|
||||
expect Void: Void = bar
|
||||
|
||||
// let Void = bar
|
||||
x
|
||||
}
|
||||
|
||||
test foo2() {
|
||||
let bar = Void
|
||||
|
||||
let x = True
|
||||
|
||||
expect Void: Void = bar
|
||||
|
||||
// let Void = bar
|
||||
x
|
||||
}
|
||||
|
||||
test foo3() {
|
||||
let bar = Void
|
||||
|
||||
let x = True
|
||||
|
||||
let Void: Void = bar
|
||||
|
||||
// let Void = bar
|
||||
x
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue