feat: Handle narrowed and hole shapes for not

This commit is contained in:
Jeremy Wall 2023-09-04 11:06:54 -04:00 committed by Jeremy Wall
parent b1d6571194
commit 902199fd98

View File

@ -62,10 +62,17 @@ fn derive_include_shape(
fn derive_not_shape(def: &NotDef, symbol_table: &mut BTreeMap<Rc<str>, Shape>) -> Shape {
let shape = def.expr.as_ref().derive_shape(symbol_table);
if let Shape::Boolean(b) = shape {
Shape::Boolean(PositionedItem::new(!b.val, def.pos.clone()))
} else {
// TODO(jwall): Display implementations for shapes.
if let Shape::Boolean(b) = &shape {
return Shape::Boolean(PositionedItem::new(!b.val, def.pos.clone()));
} else if let Shape::Hole(_) = &shape {
return Shape::Boolean(PositionedItem::new(true, def.pos.clone()));
} else if let Shape::Narrowed(shape_list) = &shape {
for s in shape_list.types.iter() {
if let Shape::Boolean(b) = s {
return Shape::Boolean(PositionedItem::new(!b.val, def.pos.clone()));
}
}
};
Shape::TypeErr(
def.pos.clone(),
format!(
@ -74,7 +81,6 @@ fn derive_not_shape(def: &NotDef, symbol_table: &mut BTreeMap<Rc<str>, Shape>) -
),
)
}
}
fn derive_copy_shape(def: &CopyDef, symbol_table: &mut BTreeMap<Rc<str>, Shape>) -> Shape {
let base_shape = def.selector.derive_shape(symbol_table);