Fix list add-assign type checking
This commit is contained in:
parent
3b7e75c41c
commit
9a4196fb2a
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user