diff --git a/dust-lang/src/abstract_tree/assignment.rs b/dust-lang/src/abstract_tree/assignment.rs
index fbc4eec..f4199a1 100644
--- a/dust-lang/src/abstract_tree/assignment.rs
+++ b/dust-lang/src/abstract_tree/assignment.rs
@@ -9,7 +9,7 @@ use crate::{
Context, Value,
};
-use super::{AbstractNode, Evaluation, Expression, Statement, Type, TypeConstructor, WithPosition};
+use super::{AbstractNode, Evaluation, Statement, Type, TypeConstructor, WithPosition};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Assignment {
@@ -54,46 +54,10 @@ impl AbstractNode for Assignment {
context.set_type(self.identifier.node.clone(), r#type)?;
} else {
return Err(ValidationError::CannotAssignToNone(
- self.statement.position(),
+ self.statement.last_evaluated_statement().position(),
));
};
- let relevant_statement = self.statement.last_evaluated_statement();
-
- if let (Some(constructor), Statement::Expression(Expression::FunctionCall(function_call))) =
- (&self.constructor, relevant_statement)
- {
- let declared_type = constructor.clone().construct(context)?;
- let function_type = function_call
- .node
- .function_expression()
- .expected_type(context)?;
-
- if let Some(Type::Function {
- return_type,
- type_parameters: Some(type_parameters),
- ..
- }) = function_type
- {
- if let Some(Type::Generic { identifier, .. }) = return_type.map(|r#box| *r#box) {
- let returned_parameter = type_parameters
- .into_iter()
- .find(|parameter| parameter == &identifier);
-
- if let Some(parameter) = returned_parameter {
- context.set_type(parameter, declared_type)?;
-
- return Ok(());
- }
- }
- } else {
- return Err(ValidationError::ExpectedFunction {
- actual: function_type.unwrap(),
- position: function_call.position,
- });
- }
- }
-
Ok(())
}
diff --git a/dust-lang/src/abstract_tree/function_call.rs b/dust-lang/src/abstract_tree/function_call.rs
index 6033d16..5be7fe1 100644
--- a/dust-lang/src/abstract_tree/function_call.rs
+++ b/dust-lang/src/abstract_tree/function_call.rs
@@ -132,13 +132,13 @@ impl AbstractNode for FunctionCall {
(None, None) => {}
}
- Ok(())
- } else {
- Err(ValidationError::ExpectedFunction {
- actual: function_node_type,
- position: self.function_expression.position(),
- })
+ return Ok(());
}
+
+ Err(ValidationError::ExpectedFunction {
+ actual: function_node_type,
+ position: self.function_expression.position(),
+ })
}
fn evaluate(
@@ -244,12 +244,12 @@ impl AbstractNode for FunctionCall {
.map(|option| option.map(|value| Evaluation::Return(value)));
}
- return Err(RuntimeError::ValidationFailure(
+ Err(RuntimeError::ValidationFailure(
ValidationError::ExpectedFunction {
actual: value.r#type(context)?,
position: function_position,
},
- ));
+ ))
}
fn expected_type(&self, context: &Context) -> Result