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,16 +142,31 @@ impl ExpectedType for FunctionCall {
..
} = *return_type.clone()
{
for (constructor, identifier) in self
.type_arguments
.as_ref()
.unwrap()
.into_iter()
.zip(type_parameters.unwrap().into_iter())
if let (Some(type_arguments), Some(type_parameters)) =
(&self.type_arguments, &type_parameters)
{
if return_identifier == identifier {
for (constructor, identifier) in
type_arguments.into_iter().zip(type_parameters.into_iter())
{
if &return_identifier == identifier {
let concrete_type = constructor.clone().construct(&context)?;
return Ok(Type::Generic {
identifier: identifier.clone(),
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)),
@ -159,6 +174,7 @@ impl ExpectedType for FunctionCall {
}
}
}
}
Ok(*return_type)
} else {

View File

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