From d753d3a2323afc5d835481a042d60480d0665413 Mon Sep 17 00:00:00 2001 From: IsaacShelton Date: Sat, 21 Dec 2024 23:58:21 -0600 Subject: [PATCH] Cleaned up some error handling code and continued to work on type classes design --- src/resolve/error.rs | 12 ++++++++++++ src/resolve/expr/call.rs | 10 ++-------- src/resolve/type_definition/prepare.rs | 5 +---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/resolve/error.rs b/src/resolve/error.rs index d72f57c..1d7f652 100644 --- a/src/resolve/error.rs +++ b/src/resolve/error.rs @@ -212,6 +212,9 @@ pub enum ResolveErrorKind { DuplicateTypeName { name: String, }, + CannotCreateOutOfRangeFloat, + TypeAliasesCannotContainPolymorphs, + FailedToConformArgumentToDefaultValue, Other { message: String, }, @@ -551,6 +554,15 @@ impl Display for ResolveErrorKind { ResolveErrorKind::DuplicateTypeName { name } => { write!(f, "Duplicate type name '{}'", name)?; } + ResolveErrorKind::CannotCreateOutOfRangeFloat => { + write!(f, "Cannot create out-of-range floating-point number")?; + } + ResolveErrorKind::TypeAliasesCannotContainPolymorphs => { + write!(f, "Type aliases cannot contain polymorphs")?; + } + ResolveErrorKind::FailedToConformArgumentToDefaultValue => { + write!(f, "Failed to conform argument to default value")?; + } ResolveErrorKind::Other { message } => { write!(f, "{}", message)?; } diff --git a/src/resolve/expr/call.rs b/src/resolve/expr/call.rs index e67d7b0..c8a75c2 100644 --- a/src/resolve/expr/call.rs +++ b/src/resolve/expr/call.rs @@ -189,10 +189,7 @@ pub fn resolve_call_expr( .or_else(|_| u64::try_from(value).map(|x| x as f64)) .or_else(|_| value.to_string().parse::()) else { - return Err(ResolveErrorKind::Other { - message: format!("Cannot create out-of-range floating-point number"), - } - .at(source)); + return Err(ResolveErrorKind::CannotCreateOutOfRangeFloat.at(source)); }; return Ok(TypedExpr { @@ -283,10 +280,7 @@ pub fn resolve_call_expr( *argument = arg; } Err(_) => { - return Err(ResolveErrorKind::Other { - message: "Failed to conform argument to default value".into(), - } - .at(source)); + return Err(ResolveErrorKind::FailedToConformArgumentToDefaultValue.at(source)); } } continue; diff --git a/src/resolve/type_definition/prepare.rs b/src/resolve/type_definition/prepare.rs index b1616b5..8fd0bb1 100644 --- a/src/resolve/type_definition/prepare.rs +++ b/src/resolve/type_definition/prepare.rs @@ -201,10 +201,7 @@ fn prepare_type_alias( .insert(resolved::TypeKind::Unresolved.at(definition.value.source)); if let Some(source) = definition.value.contains_polymorph() { - return Err(ResolveErrorKind::Other { - message: "Type aliases cannot contain polymorphs".into(), - } - .at(source)); + return Err(ResolveErrorKind::TypeAliasesCannotContainPolymorphs.at(source)); } declare_type(