Skip to content

Commit

Permalink
Continued working on structure polymorph constraint enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Dec 14, 2024
1 parent d598de4 commit 8913bdb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/resolve/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ pub enum ResolveErrorKind {
operator: String,
on_type: String,
},
ConstraintsNotSatisfiedForType {
name: String,
},
Other {
message: String,
},
Expand Down Expand Up @@ -531,6 +534,9 @@ impl Display for ResolveErrorKind {
ResolveErrorKind::CannotUseOperator { operator, on_type } => {
write!(f, "Cannot use operator '{}' on type '{}'", operator, on_type)?;
}
ResolveErrorKind::ConstraintsNotSatisfiedForType { name } => {
write!(f, "Constraints not satisfied for type '{}'", name)?;
}
ResolveErrorKind::Other { message } => {
write!(f, "{}", message)?;
}
Expand Down
7 changes: 7 additions & 0 deletions src/resolve/type_ctx/find_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum FindTypeError {
Ambiguous,
RecursiveAlias(ResolvedName),
ResolveError(ResolveError),
ConstraintsNotSatisfied,
}

impl FindTypeError {
Expand All @@ -29,6 +30,12 @@ impl FindTypeError {
name: name.to_string(),
}
.at(source),
FindTypeError::ConstraintsNotSatisfied => {
ResolveErrorKind::ConstraintsNotSatisfiedForType {
name: name.to_string(),
}
.at(source)
}
FindTypeError::ResolveError(err) => err,
}
}
Expand Down
22 changes: 20 additions & 2 deletions src/resolve/type_ctx/resolve_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
ast::{self, IntegerBits},
ir::IntegerSign,
resolve::error::{ResolveError, ResolveErrorKind},
resolved,
resolved::{self, CurrentConstraints},
source_files::Source,
};
use std::borrow::Borrow;
Expand Down Expand Up @@ -35,7 +35,25 @@ impl<'a> ResolveTypeCtx<'a> {
}
ast::TypeKind::Void => Ok(resolved::TypeKind::Void),
ast::TypeKind::Named(name, arguments) => match self.find(name, arguments) {
Ok(found) => Ok(found.into_owned()),
Ok(found) => {
if let resolved::TypeKind::Structure(_, structure_ref, arguments) =
found.borrow()
{
let structure = self
.resolved_ast
.structures
.get(*structure_ref)
.expect("referenced struct to exist");

for (name, parameter) in structure.parameters.parameters.iter() {
for constraint in &parameter.constraints {
todo!("enforce type constraints for structure type usage")
}
}
}

Ok(found.into_owned())
}
Err(err) => Err(err.into_resolve_error(name, ast_type.source)),
},
ast::TypeKind::Floating(size) => Ok(resolved::TypeKind::Floating(*size)),
Expand Down

0 comments on commit 8913bdb

Please sign in to comment.