Skip to content

Commit

Permalink
Cleaned up some error handling code and continued to work on type cla…
Browse files Browse the repository at this point in the history
…sses design
  • Loading branch information
IsaacShelton committed Dec 22, 2024
1 parent 5d67677 commit d753d3a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/resolve/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ pub enum ResolveErrorKind {
DuplicateTypeName {
name: String,
},
CannotCreateOutOfRangeFloat,
TypeAliasesCannotContainPolymorphs,
FailedToConformArgumentToDefaultValue,
Other {
message: String,
},
Expand Down Expand Up @@ -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)?;
}
Expand Down
10 changes: 2 additions & 8 deletions src/resolve/expr/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f64>())
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 {
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/resolve/type_definition/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d753d3a

Please sign in to comment.