1
0

Fix list add-assign type checking

This commit is contained in:
Jeff 2023-12-16 19:40:14 -05:00
parent 3b7e75c41c
commit 9a4196fb2a
2 changed files with 18 additions and 16 deletions

View File

@ -26,6 +26,7 @@ impl AbstractTree for Assignment {
let identifier_node = node.child(0).unwrap();
let identifier = Identifier::from_syntax_node(source, identifier_node, context)?;
let identifier_type = identifier.expected_type(context)?;
let type_node = node.child(1);
let type_definition = if let Some(type_node) = type_node {
@ -74,12 +75,7 @@ impl AbstractTree for Assignment {
.map_err(|error| error.at_node(statement_node, source))?;
}
AssignmentOperator::PlusEqual => {
let identifier_type = identifier.expected_type(context)?;
if let Type::List(item_type) = type_definition.inner() {
item_type
.check(&identifier_type)
.map_err(|error| error.at_node(identifier_node, source))?;
item_type
.check(&statement_type)
.map_err(|error| error.at_node(statement_node, source))?;
@ -88,14 +84,18 @@ impl AbstractTree for Assignment {
.inner()
.check(&identifier_type)
.map_err(|error| error.at_node(identifier_node, source))?;
type_definition
.inner()
.check(&statement_type)
.map_err(|error| error.at_node(statement_node, source))?;
}
}
AssignmentOperator::MinusEqual => todo!(),
}
} else {
if let Type::List(item_type) = identifier_type {
println!("{item_type} {statement_type}");
item_type
.check(&statement_type)
.map_err(|error| error.at_node(statement_node, source))?;
}
}
Ok(Assignment {
@ -185,12 +185,6 @@ mod tests {
",
);
assert_eq!(
Err(Error::TypeCheck {
expected: Type::String,
actual: Type::Integer
}),
result
)
assert!(result.unwrap_err().is_type_check_error())
}
}

View File

@ -213,6 +213,14 @@ impl Error {
})
}
}
pub fn is_type_check_error(&self) -> bool {
match self {
Error::TypeCheck { .. } => true,
Error::WithContext { error, .. } => error.is_type_check_error(),
_ => false,
}
}
}
impl<T> From<PoisonError<T>> for Error {