diff --git a/src/resolve/error.rs b/src/resolve/error.rs index f0e9e21..2639bd6 100644 --- a/src/resolve/error.rs +++ b/src/resolve/error.rs @@ -203,6 +203,9 @@ pub enum ResolveErrorKind { operator: String, on_type: String, }, + ConstraintsNotSatisfiedForType { + name: String, + }, Other { message: String, }, @@ -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)?; } diff --git a/src/resolve/type_ctx/find_error.rs b/src/resolve/type_ctx/find_error.rs index 70edc60..1b8c2f0 100644 --- a/src/resolve/type_ctx/find_error.rs +++ b/src/resolve/type_ctx/find_error.rs @@ -10,6 +10,7 @@ pub enum FindTypeError { Ambiguous, RecursiveAlias(ResolvedName), ResolveError(ResolveError), + ConstraintsNotSatisfied, } impl FindTypeError { @@ -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, } } diff --git a/src/resolve/type_ctx/resolve_type.rs b/src/resolve/type_ctx/resolve_type.rs index 2d92d85..3a29123 100644 --- a/src/resolve/type_ctx/resolve_type.rs +++ b/src/resolve/type_ctx/resolve_type.rs @@ -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; @@ -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 ¶meter.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)),