diff --git a/dust-lang/src/abstract_tree/as.rs b/dust-lang/src/abstract_tree/as.rs
index 6858112..0d499da 100644
--- a/dust-lang/src/abstract_tree/as.rs
+++ b/dust-lang/src/abstract_tree/as.rs
@@ -27,7 +27,7 @@ impl As {
}
impl AbstractNode for As {
- fn define_types(&self, context: &Context) -> Result<(), ValidationError> {
+ fn define_types(&self, _: &Context) -> Result<(), ValidationError> {
Ok(())
}
diff --git a/dust-lang/src/abstract_tree/assignment.rs b/dust-lang/src/abstract_tree/assignment.rs
index f3182b7..5b4bed4 100644
--- a/dust-lang/src/abstract_tree/assignment.rs
+++ b/dust-lang/src/abstract_tree/assignment.rs
@@ -8,8 +8,8 @@ use crate::{
};
use super::{
- type_constructor::{RawTypeConstructor, TypeInvokationConstructor},
- AbstractNode, Evaluation, Expression, Statement, Type, TypeConstructor, WithPosition,
+ type_constructor::TypeInvokationConstructor, AbstractNode, Evaluation, Expression, Statement,
+ Type, TypeConstructor, WithPosition,
};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
@@ -74,14 +74,6 @@ impl AbstractNode for Assignment {
}
fn validate(&self, context: &Context, manage_memory: bool) -> Result<(), ValidationError> {
- if let Some(TypeConstructor::Raw(WithPosition {
- node: RawTypeConstructor::None,
- position,
- })) = &self.constructor
- {
- return Err(ValidationError::CannotAssignToNone(position.clone()));
- }
-
let relevant_statement = self.statement.last_evaluated_statement();
let statement_type = if let Some(r#type) = relevant_statement.expected_type(context)? {
r#type
@@ -144,7 +136,7 @@ impl AbstractNode for Assignment {
..
}) = function_type
{
- if let Type::Generic { identifier, .. } = *return_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);
diff --git a/dust-lang/src/abstract_tree/function_call.rs b/dust-lang/src/abstract_tree/function_call.rs
index d7811f8..638dd0c 100644
--- a/dust-lang/src/abstract_tree/function_call.rs
+++ b/dust-lang/src/abstract_tree/function_call.rs
@@ -163,10 +163,12 @@ impl AbstractNode for FunctionCall {
..
} = function_type
{
- if let Type::Generic {
+ let return_type = return_type.map(|r#box| *r#box);
+
+ if let Some(Type::Generic {
identifier: return_identifier,
..
- } = *return_type.clone()
+ }) = &return_type
{
if let (Some(type_arguments), Some(type_parameters)) =
(&self.type_arguments, &type_parameters)
@@ -174,7 +176,7 @@ impl AbstractNode for FunctionCall {
for (constructor, identifier) in
type_arguments.into_iter().zip(type_parameters.into_iter())
{
- if identifier == &return_identifier {
+ if identifier == return_identifier {
let concrete_type = constructor.clone().construct(&context)?;
return Ok(Some(Type::Generic {
@@ -190,7 +192,7 @@ impl AbstractNode for FunctionCall {
.into_iter()
.zip(type_parameters.into_iter())
{
- if identifier == return_identifier {
+ if &identifier == return_identifier {
let concrete_type =
if let Some(r#type) = expression.expected_type(context)? {
r#type
@@ -209,7 +211,7 @@ impl AbstractNode for FunctionCall {
}
}
- Ok(Some(*return_type))
+ Ok(return_type)
} else {
Err(ValidationError::ExpectedFunction {
actual: function_type,
diff --git a/dust-lang/src/abstract_tree/list_index.rs b/dust-lang/src/abstract_tree/list_index.rs
index 084f7f5..407bb55 100644
--- a/dust-lang/src/abstract_tree/list_index.rs
+++ b/dust-lang/src/abstract_tree/list_index.rs
@@ -32,19 +32,25 @@ impl AbstractNode for ListIndex {
self.collection.validate(context, _manage_memory)?;
self.index.validate(context, _manage_memory)?;
- let collection_type = self.collection.expected_type(context)?;
- let index_type = self.index.expected_type(context)?;
-
- if index_type.is_none() {
- return Err(ValidationError::CannotIndexWithVoid(self.index.position()));
- }
+ let collection_type = if let Some(r#type) = self.index.expected_type(context)? {
+ r#type
+ } else {
+ return Err(ValidationError::ExpectedExpression(
+ self.collection.position(),
+ ));
+ };
+ let index_type = if let Some(r#type) = self.index.expected_type(context)? {
+ r#type
+ } else {
+ return Err(ValidationError::ExpectedExpression(self.index.position()));
+ };
match collection_type {
Type::List {
length: _,
item_type: _,
} => {
- if index_type == Some(Type::Integer) {
+ if index_type == Type::Integer {
Ok(())
} else {
Err(ValidationError::CannotIndexWith {
@@ -69,8 +75,8 @@ impl AbstractNode for ListIndex {
_clear_variables: bool,
) -> Result