diff --git a/base/Cargo.toml b/base/Cargo.toml index 09fbdf5e46..b709ffa14d 100644 --- a/base/Cargo.toml +++ b/base/Cargo.toml @@ -12,3 +12,4 @@ documentation = "https://marwes.github.io/gluon/gluon/index.html" [dependencies] log = "0.3.6" +quick-error = "1.0.0" diff --git a/base/src/instantiate.rs b/base/src/instantiate.rs index 34b05116e2..7625ff7239 100644 --- a/base/src/instantiate.rs +++ b/base/src/instantiate.rs @@ -8,9 +8,18 @@ use types; use types::{AliasData, BuiltinType, Type, Generic, TcType, TypeEnv, merge}; use symbol::Symbol; -pub enum Error { - SelfRecursive(I), - UndefinedType(I), +quick_error! { + #[derive(Debug)] + pub enum Error { + SelfRecursive(id: Symbol) { + description("self recursive") + display("The use of self recursion in type `{}` could not be unified.", id) + } + UndefinedType(id: Symbol) { + description("undefined type") + display("Type `{}` does not exist.", id) + } + } } /// Removes type aliases from `typ` until it is an actual type @@ -36,7 +45,7 @@ pub fn remove_aliases_cow<'t>(env: &TypeEnv, typ: &'t TcType) -> Cow<'t, TcType> pub fn remove_aliases_checked(reduced_aliases: &mut Vec, env: &TypeEnv, typ: &TcType) - -> Result, Error> { + -> Result, Error> { if let Some((alias_id, _)) = typ.as_alias() { if reduced_aliases.iter().any(|name| name == alias_id) { return Err(Error::SelfRecursive(alias_id.clone())); @@ -66,7 +75,7 @@ pub fn remove_alias(env: &TypeEnv, typ: TcType) -> TcType { maybe_remove_alias(env, &typ).unwrap_or(None).unwrap_or(typ) } -pub fn maybe_remove_alias(env: &TypeEnv, typ: &TcType) -> Result, Error> { +pub fn maybe_remove_alias(env: &TypeEnv, typ: &TcType) -> Result, Error> { let maybe_alias = match **typ { Type::Alias(ref alias) if alias.args.is_empty() => Some(alias), Type::App(ref alias, ref args) => { diff --git a/base/src/lib.rs b/base/src/lib.rs index d23793c77a..3cac08b247 100644 --- a/base/src/lib.rs +++ b/base/src/lib.rs @@ -3,6 +3,8 @@ #[macro_use] extern crate log; +#[macro_use] +extern crate quick_error; pub mod ast; pub mod fixed; diff --git a/check/src/unify_type.rs b/check/src/unify_type.rs index d9620c7d07..986abdeb20 100644 --- a/check/src/unify_type.rs +++ b/check/src/unify_type.rs @@ -34,8 +34,8 @@ pub enum TypeError { SelfRecursive(I), } -impl From> for Error { - fn from(error: instantiate::Error) -> Error { +impl From for Error { + fn from(error: instantiate::Error) -> Error { UnifyError::Other(match error { instantiate::Error::UndefinedType(id) => TypeError::UndefinedType(id), instantiate::Error::SelfRecursive(id) => TypeError::SelfRecursive(id),