Skip to content

Commit a6b3beb

Browse files
committed
feat: improve list item handling
1 parent a8a1fc8 commit a6b3beb

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

crates/ltk_ritobin/src/typecheck/visitor.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -712,27 +712,31 @@ impl TypeChecker<'_> {
712712
match &mut parent.value_mut().inner {
713713
PropertyValueEnum::Container(list)
714714
| PropertyValueEnum::UnorderedContainer(UnorderedContainerValue(list)) => {
715-
let IrItem::ListItem(IrListItem(value)) = child else {
716-
eprintln!("list item must be list item");
717-
return parent;
718-
};
719-
let value = match list.item_kind == value.kind() {
720-
true => value.inner, // FIXME: span info inside all containers??
721-
false => {
722-
self.ctx.diagnostics.push(
723-
TypeMismatch {
724-
span: value.span,
725-
expected: RitoType::simple(list.item_kind),
726-
expected_span: None, // TODO: would be nice here
727-
got: RitoType::simple(value.kind()).into(),
715+
match child {
716+
IrItem::ListItem(IrListItem(value)) => {
717+
let value = match list.item_kind == value.kind() {
718+
true => value.inner, // FIXME: span info inside all containers??
719+
false => {
720+
self.ctx.diagnostics.push(
721+
TypeMismatch {
722+
span: value.span,
723+
expected: RitoType::simple(list.item_kind),
724+
expected_span: None, // TODO: would be nice here
725+
got: RitoType::simple(value.kind()).into(),
726+
}
727+
.unwrap(),
728+
);
729+
list.item_kind.default_value()
728730
}
729-
.unwrap(),
730-
);
731-
list.item_kind.default_value()
732-
}
733-
};
731+
};
734732

735-
list.items.push(value);
733+
list.items.push(value);
734+
}
735+
IrItem::Entry(IrEntry { key, value }) => {
736+
eprintln!("list item must be list item");
737+
return parent;
738+
}
739+
}
736740
}
737741
PropertyValueEnum::Struct(struct_val)
738742
| PropertyValueEnum::Embedded(EmbeddedValue(struct_val)) => {
@@ -904,7 +908,7 @@ impl Visitor for TypeChecker<'_> {
904908
match tree.kind {
905909
Kind::ErrorTree => return Visit::Skip,
906910

907-
Kind::Block => {
911+
Kind::ListBlock => {
908912
let Some((_, parent)) = parent else {
909913
self.ctx
910914
.diagnostics
@@ -930,7 +934,6 @@ impl Visitor for TypeChecker<'_> {
930934
_ => {}
931935
}
932936
}
933-
934937
Kind::ListItem => {
935938
let Some((_, parent)) = parent else {
936939
self.ctx
@@ -948,11 +951,13 @@ impl Visitor for TypeChecker<'_> {
948951
_ => None,
949952
};
950953

954+
// dbg!(color_vec_type, parent_type);
955+
951956
let value_hint = color_vec_type.or(parent_type.value_subtype());
952957

953958
match resolve_value(&mut self.ctx, tree, value_hint) {
954959
Ok(Some(item)) => {
955-
eprintln!("{indent} list q {item:?}");
960+
eprintln!("{indent} list item {item:?}");
956961
if color_vec_type.is_some() {
957962
self.list_queue.push(IrListItem(item));
958963
} else {

0 commit comments

Comments
 (0)