1
0

Continue implementing type inference

This commit is contained in:
Jeff 2024-06-19 00:22:37 -04:00
parent 69da32d414
commit b3dd610949
2 changed files with 29 additions and 12 deletions

View File

@ -142,20 +142,36 @@ impl ExpectedType for FunctionCall {
.. ..
} = *return_type.clone() } = *return_type.clone()
{ {
for (constructor, identifier) in self if let (Some(type_arguments), Some(type_parameters)) =
.type_arguments (&self.type_arguments, &type_parameters)
.as_ref()
.unwrap()
.into_iter()
.zip(type_parameters.unwrap().into_iter())
{ {
if return_identifier == identifier { for (constructor, identifier) in
let concrete_type = constructor.clone().construct(&context)?; type_arguments.into_iter().zip(type_parameters.into_iter())
{
if &return_identifier == identifier {
let concrete_type = constructor.clone().construct(&context)?;
return Ok(Type::Generic { return Ok(Type::Generic {
identifier, identifier: identifier.clone(),
concrete_type: Some(Box::new(concrete_type)), concrete_type: Some(Box::new(concrete_type)),
}); });
}
}
}
if let (None, Some(type_parameters)) = (&self.type_arguments, type_parameters) {
for (expression, identifier) in (&self.value_arguments)
.into_iter()
.zip(type_parameters.into_iter())
{
if identifier == return_identifier {
let concrete_type = expression.expected_type(context)?;
return Ok(Type::Generic {
identifier,
concrete_type: Some(Box::new(concrete_type)),
});
}
} }
} }
} }

View File

@ -1,2 +1,3 @@
foo = fn |T| (x: T) -> T { x } foo = fn |T| (x: T) -> T { x }
bar: str = foo::(str)::("hi") bar: str = foo::(str)::("hi")
baz: str = foo("hi")