fix: expect [] on a non-empty list now fails.

This commit is contained in:
microproofs
2023-04-21 17:21:08 -04:00
committed by Kasey
parent 0066765ae5
commit 9bb1a88f23
5 changed files with 103 additions and 455 deletions

View File

@@ -1824,7 +1824,7 @@ impl<'a> CodeGenerator<'a> {
value_stack,
);
} else {
pattern_stack.let_assignment("_", value_stack);
pattern_stack.list_empty(value_stack);
}
pattern_stack.merge_child(elements_stack);
@@ -4696,6 +4696,17 @@ impl<'a> CodeGenerator<'a> {
arg_stack.push(term);
}
Air::ListEmpty { .. } => {
let value = arg_stack.pop().unwrap();
let mut term = arg_stack.pop().unwrap();
term = value.delayed_choose_list(
term,
Term::Error.trace(Term::string("Expected no items for List")),
);
arg_stack.push(term);
}
Air::Tuple { tipo, count, .. } => {
let mut args = vec![];

View File

@@ -219,6 +219,9 @@ pub enum Air {
FieldsEmpty {
scope: Scope,
},
ListEmpty {
scope: Scope,
},
}
impl Air {
@@ -257,6 +260,7 @@ impl Air {
| Air::RecordAccess { scope, .. }
| Air::FieldsExpose { scope, .. }
| Air::FieldsEmpty { scope }
| Air::ListEmpty { scope }
| Air::ListAccessor { scope, .. }
| Air::ListExpose { scope, .. }
| Air::TupleAccessor { scope, .. }
@@ -301,6 +305,7 @@ impl Air {
| Air::RecordAccess { scope, .. }
| Air::FieldsExpose { scope, .. }
| Air::FieldsEmpty { scope }
| Air::ListEmpty { scope }
| Air::ListAccessor { scope, .. }
| Air::ListExpose { scope, .. }
| Air::TupleAccessor { scope, .. }
@@ -398,6 +403,7 @@ impl Air {
| Air::Finally { .. }
| Air::FieldsExpose { .. }
| Air::FieldsEmpty { .. }
| Air::ListEmpty { .. }
| Air::NoOp { .. } => None,
Air::UnOp { op, .. } => match op {
UnOp::Not => Some(

View File

@@ -781,6 +781,16 @@ impl AirStack {
self.call(void(), expect_stack, vec![tail_stack, arg_stack2])
}
pub fn list_empty(&mut self, value_stack: AirStack) {
self.new_scope();
self.air.push(Air::ListEmpty {
scope: self.scope.clone(),
});
self.merge_child(value_stack);
}
}
#[cfg(test)]