Fix type check bug
This commit is contained in:
parent
d3a9fb3a0e
commit
32127a6cda
@ -100,7 +100,15 @@ impl AbstractTree for Block {
|
||||
}
|
||||
|
||||
fn expected_type(&self, context: &Map) -> Result<Type> {
|
||||
if let Some(statement) = self.statements.last() {
|
||||
if let Some(statement) = self.statements.iter().find(|statement| {
|
||||
if let Statement::Return(_) = statement {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}) {
|
||||
statement.expected_type(context)
|
||||
} else if let Some(statement) = self.statements.last() {
|
||||
statement.expected_type(context)
|
||||
} else {
|
||||
Ok(Type::None)
|
||||
|
@ -69,7 +69,9 @@ impl AbstractTree for ValueNode {
|
||||
let body_node = child.child(child_count - 1).unwrap();
|
||||
let body = Block::from_syntax_node(source, body_node, &function_context)?;
|
||||
|
||||
return_type.inner().check(&body.expected_type(context)?)?;
|
||||
return_type
|
||||
.inner()
|
||||
.check(&body.expected_type(&function_context)?)?;
|
||||
|
||||
let r#type = Type::Function {
|
||||
parameter_types,
|
||||
@ -207,7 +209,7 @@ impl AbstractTree for ValueNode {
|
||||
}
|
||||
|
||||
fn expected_type(&self, context: &Map) -> Result<Type> {
|
||||
let type_definition = match self {
|
||||
let r#type = match self {
|
||||
ValueNode::Boolean(_) => Type::Boolean,
|
||||
ValueNode::Float(_) => Type::Float,
|
||||
ValueNode::Function(function) => function.r#type().clone(),
|
||||
@ -244,6 +246,6 @@ impl AbstractTree for ValueNode {
|
||||
ValueNode::Map(_) => Type::Map,
|
||||
};
|
||||
|
||||
Ok(type_definition)
|
||||
Ok(r#type)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user