Skip to content

Commit

Permalink
Added ability for functions to accept structures with polymorphic typ…
Browse files Browse the repository at this point in the history
…e parameters
  • Loading branch information
IsaacShelton committed Dec 11, 2024
1 parent 67e09a5 commit 7d53a40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/ast/datatype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ impl Type {
TypeKind::Pointer(inner) => inner.contains_polymorph(),
TypeKind::FixedArray(fixed_array) => fixed_array.ast_type.contains_polymorph(),
TypeKind::Void => None,
TypeKind::Named(_, _) => None,
TypeKind::Named(_, args) => args
.iter()
.flat_map(|arg| match arg {
CompileTimeArgument::Type(ty) => ty.contains_polymorph(),
CompileTimeArgument::Expr(_) => todo!("ast::Type::contains_polymorph"),
})
.next(),
TypeKind::AnonymousStruct(_) => todo!("contains_polymoph for AnonymousStruct"),
TypeKind::AnonymousUnion(_) => todo!("contains_polymorph for AnonymousUnion"),
TypeKind::AnonymousEnum(_) => todo!("contains_polymorph for AnonymousEnum"),
Expand Down
10 changes: 9 additions & 1 deletion src/resolve/polymorph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ impl PolyRecipe {
}
resolved::TypeKind::FunctionPointer(_) => todo!(),
resolved::TypeKind::Enum(_, _) => ty.clone(),
resolved::TypeKind::Structure(_, _, _) => ty.clone(),
resolved::TypeKind::Structure(human_name, structure_ref, poly_args) => {
let args = poly_args
.iter()
.map(|arg| self.resolve_type(arg))
.collect::<Result<_, _>>()?;

resolved::TypeKind::Structure(human_name.clone(), *structure_ref, args)
.at(ty.source)
}
resolved::TypeKind::TypeAlias(_, _) => ty.clone(),
resolved::TypeKind::Polymorph(name, _) => {
let Some(value) = polymorphs.get(name) else {
Expand Down

0 comments on commit 7d53a40

Please sign in to comment.