summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dhall/src/error.rs60
-rw-r--r--dhall/src/error/mod.rs169
-rw-r--r--dhall/src/error/text/AnnotMismatch.txt (renamed from dhall/src/errors/AnnotMismatch.txt)0
-rw-r--r--dhall/src/error/text/CantTextAppend.txt (renamed from dhall/src/errors/CantTextAppend.txt)0
-rw-r--r--dhall/src/error/text/DuplicateAlternative.txt (renamed from dhall/src/errors/DuplicateAlternative.txt)0
-rw-r--r--dhall/src/error/text/FieldCollision.txt (renamed from dhall/src/errors/FieldCollision.txt)0
-rw-r--r--dhall/src/error/text/HandlerInputTypeMismatch.txt (renamed from dhall/src/errors/HandlerInputTypeMismatch.txt)0
-rw-r--r--dhall/src/error/text/HandlerNotAFunction.txt (renamed from dhall/src/errors/HandlerNotAFunction.txt)0
-rw-r--r--dhall/src/error/text/HandlerOutputTypeMismatch.txt (renamed from dhall/src/errors/HandlerOutputTypeMismatch.txt)0
-rw-r--r--dhall/src/error/text/IfBranchMismatch.txt (renamed from dhall/src/errors/IfBranchMismatch.txt)0
-rw-r--r--dhall/src/error/text/IfBranchMustBeTerm.txt (renamed from dhall/src/errors/IfBranchMustBeTerm.txt)0
-rw-r--r--dhall/src/error/text/InvalidAlterantive.txt (renamed from dhall/src/errors/InvalidAlterantive.txt)0
-rw-r--r--dhall/src/error/text/InvalidAlterantiveType.txt (renamed from dhall/src/errors/InvalidAlterantiveType.txt)0
-rw-r--r--dhall/src/error/text/InvalidField.txt (renamed from dhall/src/errors/InvalidField.txt)0
-rw-r--r--dhall/src/error/text/InvalidFieldType.txt (renamed from dhall/src/errors/InvalidFieldType.txt)0
-rw-r--r--dhall/src/error/text/InvalidInputType.txt (renamed from dhall/src/errors/InvalidInputType.txt)0
-rw-r--r--dhall/src/error/text/InvalidListElement.txt (renamed from dhall/src/errors/InvalidListElement.txt)0
-rw-r--r--dhall/src/error/text/InvalidListType.txt (renamed from dhall/src/errors/InvalidListType.txt)0
-rw-r--r--dhall/src/error/text/InvalidOptionType.txt (renamed from dhall/src/errors/InvalidOptionType.txt)0
-rw-r--r--dhall/src/error/text/InvalidOptionalElement.txt (renamed from dhall/src/errors/InvalidOptionalElement.txt)0
-rw-r--r--dhall/src/error/text/InvalidOptionalLiteral.txt (renamed from dhall/src/errors/InvalidOptionalLiteral.txt)0
-rw-r--r--dhall/src/error/text/InvalidOutputType.txt (renamed from dhall/src/errors/InvalidOutputType.txt)0
-rw-r--r--dhall/src/error/text/InvalidPredicate.txt (renamed from dhall/src/errors/InvalidPredicate.txt)0
-rw-r--r--dhall/src/error/text/MissingField.txt (renamed from dhall/src/errors/MissingField.txt)0
-rw-r--r--dhall/src/error/text/MissingHandler.txt (renamed from dhall/src/errors/MissingHandler.txt)0
-rw-r--r--dhall/src/error/text/MustCombineARecord.txt (renamed from dhall/src/errors/MustCombineARecord.txt)0
-rw-r--r--dhall/src/error/text/MustMergeARecord.txt (renamed from dhall/src/errors/MustMergeARecord.txt)0
-rw-r--r--dhall/src/error/text/MustMergeUnion.txt (renamed from dhall/src/errors/MustMergeUnion.txt)0
-rw-r--r--dhall/src/error/text/NoDependentLet.txt (renamed from dhall/src/errors/NoDependentLet.txt)0
-rw-r--r--dhall/src/error/text/NoDependentTypes.txt (renamed from dhall/src/errors/NoDependentTypes.txt)0
-rw-r--r--dhall/src/error/text/NotAFunction.txt (renamed from dhall/src/errors/NotAFunction.txt)0
-rw-r--r--dhall/src/error/text/NotARecord.txt (renamed from dhall/src/errors/NotARecord.txt)0
-rw-r--r--dhall/src/error/text/TypeMismatch.txt (renamed from dhall/src/errors/TypeMismatch.txt)0
-rw-r--r--dhall/src/error/text/UnboundVariable.txt (renamed from dhall/src/errors/UnboundVariable.txt)0
-rw-r--r--dhall/src/error/text/Untyped.txt (renamed from dhall/src/errors/Untyped.txt)0
-rw-r--r--dhall/src/error/text/UnusedHandler.txt (renamed from dhall/src/errors/UnusedHandler.txt)0
-rw-r--r--dhall/src/lib.rs1
-rw-r--r--dhall/src/phase/binary.rs17
-rw-r--r--dhall/src/phase/mod.rs8
-rw-r--r--dhall/src/phase/resolve.rs11
-rw-r--r--dhall/src/phase/typecheck.rs114
-rw-r--r--dhall/src/traits/dynamic_type.rs4
42 files changed, 196 insertions, 188 deletions
diff --git a/dhall/src/error.rs b/dhall/src/error.rs
deleted file mode 100644
index 8497a91..0000000
--- a/dhall/src/error.rs
+++ /dev/null
@@ -1,60 +0,0 @@
-use std::io::Error as IOError;
-
-use dhall_syntax::ParseError;
-
-use crate::phase::binary::DecodeError;
-use crate::phase::resolve::ImportError;
-use crate::phase::typecheck::TypeError;
-
-pub type Result<T> = std::result::Result<T, Error>;
-
-#[derive(Debug)]
-#[non_exhaustive]
-pub enum Error {
- IO(IOError),
- Parse(ParseError),
- Decode(DecodeError),
- Resolve(ImportError),
- Typecheck(TypeError),
- Deserialize(String),
-}
-
-impl std::fmt::Display for Error {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- match self {
- Error::IO(err) => write!(f, "{}", err),
- Error::Parse(err) => write!(f, "{}", err),
- Error::Decode(err) => write!(f, "{:?}", err),
- Error::Resolve(err) => write!(f, "{:?}", err),
- Error::Typecheck(err) => write!(f, "{:?}", err),
- Error::Deserialize(err) => write!(f, "{}", err),
- }
- }
-}
-
-impl std::error::Error for Error {}
-impl From<IOError> for Error {
- fn from(err: IOError) -> Error {
- Error::IO(err)
- }
-}
-impl From<ParseError> for Error {
- fn from(err: ParseError) -> Error {
- Error::Parse(err)
- }
-}
-impl From<DecodeError> for Error {
- fn from(err: DecodeError) -> Error {
- Error::Decode(err)
- }
-}
-impl From<ImportError> for Error {
- fn from(err: ImportError) -> Error {
- Error::Resolve(err)
- }
-}
-impl From<TypeError> for Error {
- fn from(err: TypeError) -> Error {
- Error::Typecheck(err)
- }
-}
diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs
new file mode 100644
index 0000000..e70b9a9
--- /dev/null
+++ b/dhall/src/error/mod.rs
@@ -0,0 +1,169 @@
+use std::io::Error as IOError;
+
+use dhall_syntax::{BinOp, Import, Label, ParseError, V};
+
+use crate::phase::resolve::ImportStack;
+use crate::phase::typecheck::TypecheckContext;
+use crate::phase::{Normalized, Type, Typed};
+
+pub type Result<T> = std::result::Result<T, Error>;
+
+#[derive(Debug)]
+#[non_exhaustive]
+pub enum Error {
+ IO(IOError),
+ Parse(ParseError),
+ Decode(DecodeError),
+ Resolve(ImportError),
+ Typecheck(TypeError),
+ Deserialize(String),
+}
+
+#[derive(Debug)]
+pub enum ImportError {
+ Recursive(Import, Box<Error>),
+ UnexpectedImport(Import),
+ ImportCycle(ImportStack, Import),
+}
+
+#[derive(Debug)]
+pub enum DecodeError {
+ CBORError(serde_cbor::error::Error),
+ WrongFormatError(String),
+}
+
+/// A structured type error that includes context
+#[derive(Debug)]
+pub struct TypeError {
+ type_message: TypeMessage,
+ context: TypecheckContext,
+}
+
+/// The specific type error
+#[derive(Debug)]
+pub(crate) enum TypeMessage {
+ UnboundVariable(V<Label>),
+ InvalidInputType(Normalized),
+ InvalidOutputType(Normalized),
+ NotAFunction(Typed),
+ TypeMismatch(Typed, Normalized, Typed),
+ AnnotMismatch(Typed, Normalized),
+ Untyped,
+ InvalidListElement(usize, Normalized, Typed),
+ InvalidListType(Normalized),
+ InvalidOptionalType(Normalized),
+ InvalidPredicate(Typed),
+ IfBranchMismatch(Typed, Typed),
+ IfBranchMustBeTerm(bool, Typed),
+ InvalidFieldType(Label, Type),
+ NotARecord(Label, Normalized),
+ MissingRecordField(Label, Typed),
+ MissingUnionField(Label, Normalized),
+ BinOpTypeMismatch(BinOp, Typed),
+ NoDependentTypes(Normalized, Normalized),
+ InvalidTextInterpolation(Typed),
+ Sort,
+ Unimplemented,
+}
+
+impl TypeError {
+ pub(crate) fn new(
+ context: &TypecheckContext,
+ type_message: TypeMessage,
+ ) -> Self {
+ TypeError {
+ context: context.clone(),
+ type_message,
+ }
+ }
+}
+
+impl From<TypeError> for std::option::NoneError {
+ fn from(_: TypeError) -> std::option::NoneError {
+ std::option::NoneError
+ }
+}
+
+impl std::error::Error for TypeMessage {
+ fn description(&self) -> &str {
+ use TypeMessage::*;
+ match *self {
+ // UnboundVariable => "Unbound variable",
+ InvalidInputType(_) => "Invalid function input",
+ InvalidOutputType(_) => "Invalid function output",
+ NotAFunction(_) => "Not a function",
+ TypeMismatch(_, _, _) => "Wrong type of function argument",
+ _ => "Unhandled error",
+ }
+ }
+}
+
+impl std::fmt::Display for TypeMessage {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ match self {
+ // UnboundVariable(_) => {
+ // f.write_str(include_str!("errors/UnboundVariable.txt"))
+ // }
+ // TypeMismatch(e0, e1, e2) => {
+ // let template = include_str!("errors/TypeMismatch.txt");
+ // let s = template
+ // .replace("$txt0", &format!("{}", e0.as_expr()))
+ // .replace("$txt1", &format!("{}", e1.as_expr()))
+ // .replace("$txt2", &format!("{}", e2.as_expr()))
+ // .replace(
+ // "$txt3",
+ // &format!(
+ // "{}",
+ // e2.get_type()
+ // .unwrap()
+ // .as_normalized()
+ // .unwrap()
+ // .as_expr()
+ // ),
+ // );
+ // f.write_str(&s)
+ // }
+ _ => f.write_str("Unhandled error message"),
+ }
+ }
+}
+
+impl std::fmt::Display for Error {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ match self {
+ Error::IO(err) => write!(f, "{}", err),
+ Error::Parse(err) => write!(f, "{}", err),
+ Error::Decode(err) => write!(f, "{:?}", err),
+ Error::Resolve(err) => write!(f, "{:?}", err),
+ Error::Typecheck(err) => write!(f, "{:?}", err),
+ Error::Deserialize(err) => write!(f, "{}", err),
+ }
+ }
+}
+
+impl std::error::Error for Error {}
+impl From<IOError> for Error {
+ fn from(err: IOError) -> Error {
+ Error::IO(err)
+ }
+}
+impl From<ParseError> for Error {
+ fn from(err: ParseError) -> Error {
+ Error::Parse(err)
+ }
+}
+impl From<DecodeError> for Error {
+ fn from(err: DecodeError) -> Error {
+ Error::Decode(err)
+ }
+}
+impl From<ImportError> for Error {
+ fn from(err: ImportError) -> Error {
+ Error::Resolve(err)
+ }
+}
+impl From<TypeError> for Error {
+ fn from(err: TypeError) -> Error {
+ Error::Typecheck(err)
+ }
+}
diff --git a/dhall/src/errors/AnnotMismatch.txt b/dhall/src/error/text/AnnotMismatch.txt
index 4904bf8..4904bf8 100644
--- a/dhall/src/errors/AnnotMismatch.txt
+++ b/dhall/src/error/text/AnnotMismatch.txt
diff --git a/dhall/src/errors/CantTextAppend.txt b/dhall/src/error/text/CantTextAppend.txt
index 26b9ceb..26b9ceb 100644
--- a/dhall/src/errors/CantTextAppend.txt
+++ b/dhall/src/error/text/CantTextAppend.txt
diff --git a/dhall/src/errors/DuplicateAlternative.txt b/dhall/src/error/text/DuplicateAlternative.txt
index 077f8aa..077f8aa 100644
--- a/dhall/src/errors/DuplicateAlternative.txt
+++ b/dhall/src/error/text/DuplicateAlternative.txt
diff --git a/dhall/src/errors/FieldCollision.txt b/dhall/src/error/text/FieldCollision.txt
index 2b2d260..2b2d260 100644
--- a/dhall/src/errors/FieldCollision.txt
+++ b/dhall/src/error/text/FieldCollision.txt
diff --git a/dhall/src/errors/HandlerInputTypeMismatch.txt b/dhall/src/error/text/HandlerInputTypeMismatch.txt
index 7d3525b..7d3525b 100644
--- a/dhall/src/errors/HandlerInputTypeMismatch.txt
+++ b/dhall/src/error/text/HandlerInputTypeMismatch.txt
diff --git a/dhall/src/errors/HandlerNotAFunction.txt b/dhall/src/error/text/HandlerNotAFunction.txt
index ff87443..ff87443 100644
--- a/dhall/src/errors/HandlerNotAFunction.txt
+++ b/dhall/src/error/text/HandlerNotAFunction.txt
diff --git a/dhall/src/errors/HandlerOutputTypeMismatch.txt b/dhall/src/error/text/HandlerOutputTypeMismatch.txt
index f359459..f359459 100644
--- a/dhall/src/errors/HandlerOutputTypeMismatch.txt
+++ b/dhall/src/error/text/HandlerOutputTypeMismatch.txt
diff --git a/dhall/src/errors/IfBranchMismatch.txt b/dhall/src/error/text/IfBranchMismatch.txt
index a95b130..a95b130 100644
--- a/dhall/src/errors/IfBranchMismatch.txt
+++ b/dhall/src/error/text/IfBranchMismatch.txt
diff --git a/dhall/src/errors/IfBranchMustBeTerm.txt b/dhall/src/error/text/IfBranchMustBeTerm.txt
index 4c15881..4c15881 100644
--- a/dhall/src/errors/IfBranchMustBeTerm.txt
+++ b/dhall/src/error/text/IfBranchMustBeTerm.txt
diff --git a/dhall/src/errors/InvalidAlterantive.txt b/dhall/src/error/text/InvalidAlterantive.txt
index 391fc3a..391fc3a 100644
--- a/dhall/src/errors/InvalidAlterantive.txt
+++ b/dhall/src/error/text/InvalidAlterantive.txt
diff --git a/dhall/src/errors/InvalidAlterantiveType.txt b/dhall/src/error/text/InvalidAlterantiveType.txt
index f5dadef..f5dadef 100644
--- a/dhall/src/errors/InvalidAlterantiveType.txt
+++ b/dhall/src/error/text/InvalidAlterantiveType.txt
diff --git a/dhall/src/errors/InvalidField.txt b/dhall/src/error/text/InvalidField.txt
index bfbf106..bfbf106 100644
--- a/dhall/src/errors/InvalidField.txt
+++ b/dhall/src/error/text/InvalidField.txt
diff --git a/dhall/src/errors/InvalidFieldType.txt b/dhall/src/error/text/InvalidFieldType.txt
index 4f76a64..4f76a64 100644
--- a/dhall/src/errors/InvalidFieldType.txt
+++ b/dhall/src/error/text/InvalidFieldType.txt
diff --git a/dhall/src/errors/InvalidInputType.txt b/dhall/src/error/text/InvalidInputType.txt
index eabafa4..eabafa4 100644
--- a/dhall/src/errors/InvalidInputType.txt
+++ b/dhall/src/error/text/InvalidInputType.txt
diff --git a/dhall/src/errors/InvalidListElement.txt b/dhall/src/error/text/InvalidListElement.txt
index 59db7b7..59db7b7 100644
--- a/dhall/src/errors/InvalidListElement.txt
+++ b/dhall/src/error/text/InvalidListElement.txt
diff --git a/dhall/src/errors/InvalidListType.txt b/dhall/src/error/text/InvalidListType.txt
index 676647e..676647e 100644
--- a/dhall/src/errors/InvalidListType.txt
+++ b/dhall/src/error/text/InvalidListType.txt
diff --git a/dhall/src/errors/InvalidOptionType.txt b/dhall/src/error/text/InvalidOptionType.txt
index 3bc81de..3bc81de 100644
--- a/dhall/src/errors/InvalidOptionType.txt
+++ b/dhall/src/error/text/InvalidOptionType.txt
diff --git a/dhall/src/errors/InvalidOptionalElement.txt b/dhall/src/error/text/InvalidOptionalElement.txt
index 0254220..0254220 100644
--- a/dhall/src/errors/InvalidOptionalElement.txt
+++ b/dhall/src/error/text/InvalidOptionalElement.txt
diff --git a/dhall/src/errors/InvalidOptionalLiteral.txt b/dhall/src/error/text/InvalidOptionalLiteral.txt
index 41c0fdc..41c0fdc 100644
--- a/dhall/src/errors/InvalidOptionalLiteral.txt
+++ b/dhall/src/error/text/InvalidOptionalLiteral.txt
diff --git a/dhall/src/errors/InvalidOutputType.txt b/dhall/src/error/text/InvalidOutputType.txt
index dd2695d..dd2695d 100644
--- a/dhall/src/errors/InvalidOutputType.txt
+++ b/dhall/src/error/text/InvalidOutputType.txt
diff --git a/dhall/src/errors/InvalidPredicate.txt b/dhall/src/error/text/InvalidPredicate.txt
index 4c15881..4c15881 100644
--- a/dhall/src/errors/InvalidPredicate.txt
+++ b/dhall/src/error/text/InvalidPredicate.txt
diff --git a/dhall/src/errors/MissingField.txt b/dhall/src/error/text/MissingField.txt
index de14a33..de14a33 100644
--- a/dhall/src/errors/MissingField.txt
+++ b/dhall/src/error/text/MissingField.txt
diff --git a/dhall/src/errors/MissingHandler.txt b/dhall/src/error/text/MissingHandler.txt
index 433445e..433445e 100644
--- a/dhall/src/errors/MissingHandler.txt
+++ b/dhall/src/error/text/MissingHandler.txt
diff --git a/dhall/src/errors/MustCombineARecord.txt b/dhall/src/error/text/MustCombineARecord.txt
index 141b969..141b969 100644
--- a/dhall/src/errors/MustCombineARecord.txt
+++ b/dhall/src/error/text/MustCombineARecord.txt
diff --git a/dhall/src/errors/MustMergeARecord.txt b/dhall/src/error/text/MustMergeARecord.txt
index 79094bd..79094bd 100644
--- a/dhall/src/errors/MustMergeARecord.txt
+++ b/dhall/src/error/text/MustMergeARecord.txt
diff --git a/dhall/src/errors/MustMergeUnion.txt b/dhall/src/error/text/MustMergeUnion.txt
index 68df70c..68df70c 100644
--- a/dhall/src/errors/MustMergeUnion.txt
+++ b/dhall/src/error/text/MustMergeUnion.txt
diff --git a/dhall/src/errors/NoDependentLet.txt b/dhall/src/error/text/NoDependentLet.txt
index fdc65b4..fdc65b4 100644
--- a/dhall/src/errors/NoDependentLet.txt
+++ b/dhall/src/error/text/NoDependentLet.txt
diff --git a/dhall/src/errors/NoDependentTypes.txt b/dhall/src/error/text/NoDependentTypes.txt
index 435bdcb..435bdcb 100644
--- a/dhall/src/errors/NoDependentTypes.txt
+++ b/dhall/src/error/text/NoDependentTypes.txt
diff --git a/dhall/src/errors/NotAFunction.txt b/dhall/src/error/text/NotAFunction.txt
index dd2695d..dd2695d 100644
--- a/dhall/src/errors/NotAFunction.txt
+++ b/dhall/src/error/text/NotAFunction.txt
diff --git a/dhall/src/errors/NotARecord.txt b/dhall/src/error/text/NotARecord.txt
index e0eebc8..e0eebc8 100644
--- a/dhall/src/errors/NotARecord.txt
+++ b/dhall/src/error/text/NotARecord.txt
diff --git a/dhall/src/errors/TypeMismatch.txt b/dhall/src/error/text/TypeMismatch.txt
index 4904bf8..4904bf8 100644
--- a/dhall/src/errors/TypeMismatch.txt
+++ b/dhall/src/error/text/TypeMismatch.txt
diff --git a/dhall/src/errors/UnboundVariable.txt b/dhall/src/error/text/UnboundVariable.txt
index bd7d483..bd7d483 100644
--- a/dhall/src/errors/UnboundVariable.txt
+++ b/dhall/src/error/text/UnboundVariable.txt
diff --git a/dhall/src/errors/Untyped.txt b/dhall/src/error/text/Untyped.txt
index 4904bf8..4904bf8 100644
--- a/dhall/src/errors/Untyped.txt
+++ b/dhall/src/error/text/Untyped.txt
diff --git a/dhall/src/errors/UnusedHandler.txt b/dhall/src/error/text/UnusedHandler.txt
index 2e46a12..2e46a12 100644
--- a/dhall/src/errors/UnusedHandler.txt
+++ b/dhall/src/error/text/UnusedHandler.txt
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs
index ec110f7..9f9c315 100644
--- a/dhall/src/lib.rs
+++ b/dhall/src/lib.rs
@@ -123,7 +123,6 @@
#[macro_use]
mod tests;
-/// When manipulating Dhall expressions goes wrong.
pub mod error;
mod phase;
mod serde;
diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs
index 9c31d4c..30aa7a0 100644
--- a/dhall/src/phase/binary.rs
+++ b/dhall/src/phase/binary.rs
@@ -1,14 +1,15 @@
-use dhall_syntax::*;
-use itertools::*;
+use itertools::Itertools;
use serde_cbor::value::value as cbor;
-type ParsedExpr = SubExpr<X, Import>;
+use dhall_syntax::{
+ rc, ExprF, FilePrefix, Hash, Import, ImportHashed, ImportLocation,
+ ImportMode, Integer, InterpolatedText, Label, Natural, Scheme, SubExpr,
+ URL, V, X,
+};
-#[derive(Debug)]
-pub enum DecodeError {
- CBORError(serde_cbor::error::Error),
- WrongFormatError(String),
-}
+use crate::error::DecodeError;
+
+type ParsedExpr = SubExpr<X, Import>;
pub fn decode(data: &[u8]) -> Result<ParsedExpr, DecodeError> {
match serde_cbor::de::from_slice(data) {
diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs
index 0b6eca6..4262dc1 100644
--- a/dhall/src/phase/mod.rs
+++ b/dhall/src/phase/mod.rs
@@ -4,13 +4,11 @@ use std::path::Path;
use dhall_syntax::{Const, Import, Span, SubExpr, X};
-use crate::error::Error;
+use crate::error::{Error, ImportError, TypeError, TypeMessage};
use normalize::{AlphaVar, Thunk, Value};
-use resolve::{ImportError, ImportRoot};
-use typecheck::{
- const_to_typed, type_of_const, TypeError, TypeMessage, TypecheckContext,
-};
+use resolve::ImportRoot;
+use typecheck::{const_to_typed, type_of_const, TypecheckContext};
pub(crate) mod binary;
pub(crate) mod normalize;
diff --git a/dhall/src/phase/resolve.rs b/dhall/src/phase/resolve.rs
index afb49cb..5ab03ac 100644
--- a/dhall/src/phase/resolve.rs
+++ b/dhall/src/phase/resolve.rs
@@ -3,16 +3,9 @@ use std::path::{Path, PathBuf};
use dhall_syntax::Import;
-use crate::error::Error;
+use crate::error::{Error, ImportError};
use crate::phase::{Normalized, Parsed, Resolved};
-#[derive(Debug)]
-pub enum ImportError {
- Recursive(Import, Box<Error>),
- UnexpectedImport(Import),
- ImportCycle(ImportStack, Import),
-}
-
/// A root from which to resolve relative imports.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ImportRoot {
@@ -21,7 +14,7 @@ pub enum ImportRoot {
type ImportCache = HashMap<Import, Normalized>;
-type ImportStack = Vec<Import>;
+pub(crate) type ImportStack = Vec<Import>;
fn resolve_import(
import: &Import,
diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs
index 6b12077..aee9892 100644
--- a/dhall/src/phase/typecheck.rs
+++ b/dhall/src/phase/typecheck.rs
@@ -2,19 +2,20 @@
use std::borrow::Borrow;
use std::borrow::Cow;
use std::collections::BTreeMap;
-use std::fmt;
+use dhall_proc_macros as dhall;
+use dhall_syntax::context::Context;
+use dhall_syntax::{
+ rc, Builtin, Const, Expr, ExprF, InterpolatedTextContents, Label, Span,
+ SubExpr, V, X,
+};
+
+use crate::error::{TypeError, TypeMessage};
use crate::phase::normalize::{
AlphaVar, NormalizationContext, Thunk, TypeThunk, Value,
};
-use crate::phase::*;
+use crate::phase::{Normalized, Resolved, Type, TypeInternal, Typed};
use crate::traits::DynamicType;
-use dhall_proc_macros as dhall;
-use dhall_syntax;
-use dhall_syntax::context::Context;
-use dhall_syntax::*;
-
-use self::TypeMessage::*;
impl TypeThunk {
fn to_type(&self, ctx: &TypecheckContext) -> Result<Type, TypeError> {
@@ -244,6 +245,7 @@ pub(crate) enum TypeIntermediate {
impl TypeIntermediate {
fn typecheck(self) -> Result<Typed, TypeError> {
+ use crate::error::TypeMessage::*;
let mkerr = |ctx, msg| TypeError::new(ctx, msg);
Ok(match &self {
TypeIntermediate::Pi(ctx, x, ta, tb) => {
@@ -503,6 +505,7 @@ fn type_last_layer(
ctx: &TypecheckContext,
e: ExprF<Typed, Label, Normalized>,
) -> Result<Ret, TypeError> {
+ use crate::error::TypeMessage::*;
use dhall_syntax::BinOp::*;
use dhall_syntax::Builtin::*;
use dhall_syntax::ExprF::*;
@@ -801,101 +804,6 @@ pub(crate) fn skip_typecheck(e: Resolved) -> Typed {
Typed::from_thunk_untyped(Thunk::new(NormalizationContext::new(), e.0))
}
-/// The specific type error
-#[derive(Debug)]
-pub(crate) enum TypeMessage {
- UnboundVariable(V<Label>),
- InvalidInputType(Normalized),
- InvalidOutputType(Normalized),
- NotAFunction(Typed),
- TypeMismatch(Typed, Normalized, Typed),
- AnnotMismatch(Typed, Normalized),
- Untyped,
- InvalidListElement(usize, Normalized, Typed),
- InvalidListType(Normalized),
- InvalidOptionalType(Normalized),
- InvalidPredicate(Typed),
- IfBranchMismatch(Typed, Typed),
- IfBranchMustBeTerm(bool, Typed),
- InvalidFieldType(Label, Type),
- NotARecord(Label, Normalized),
- MissingRecordField(Label, Typed),
- MissingUnionField(Label, Normalized),
- BinOpTypeMismatch(BinOp, Typed),
- NoDependentTypes(Normalized, Normalized),
- InvalidTextInterpolation(Typed),
- Sort,
- Unimplemented,
-}
-
-/// A structured type error that includes context
-#[derive(Debug)]
-pub struct TypeError {
- type_message: TypeMessage,
- context: TypecheckContext,
-}
-
-impl TypeError {
- pub(crate) fn new(
- context: &TypecheckContext,
- type_message: TypeMessage,
- ) -> Self {
- TypeError {
- context: context.clone(),
- type_message,
- }
- }
-}
-
-impl From<TypeError> for std::option::NoneError {
- fn from(_: TypeError) -> std::option::NoneError {
- std::option::NoneError
- }
-}
-
-impl ::std::error::Error for TypeMessage {
- fn description(&self) -> &str {
- match *self {
- // UnboundVariable => "Unbound variable",
- InvalidInputType(_) => "Invalid function input",
- InvalidOutputType(_) => "Invalid function output",
- NotAFunction(_) => "Not a function",
- TypeMismatch(_, _, _) => "Wrong type of function argument",
- _ => "Unhandled error",
- }
- }
-}
-
-impl fmt::Display for TypeMessage {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- match self {
- // UnboundVariable(_) => {
- // f.write_str(include_str!("errors/UnboundVariable.txt"))
- // }
- // TypeMismatch(e0, e1, e2) => {
- // let template = include_str!("errors/TypeMismatch.txt");
- // let s = template
- // .replace("$txt0", &format!("{}", e0.as_expr()))
- // .replace("$txt1", &format!("{}", e1.as_expr()))
- // .replace("$txt2", &format!("{}", e2.as_expr()))
- // .replace(
- // "$txt3",
- // &format!(
- // "{}",
- // e2.get_type()
- // .unwrap()
- // .as_normalized()
- // .unwrap()
- // .as_expr()
- // ),
- // );
- // f.write_str(&s)
- // }
- _ => f.write_str("Unhandled error message"),
- }
- }
-}
-
#[cfg(test)]
mod spec_tests {
#![rustfmt::skip]
diff --git a/dhall/src/traits/dynamic_type.rs b/dhall/src/traits/dynamic_type.rs
index 3f8d117..7763a28 100644
--- a/dhall/src/traits/dynamic_type.rs
+++ b/dhall/src/traits/dynamic_type.rs
@@ -1,5 +1,5 @@
-use crate::phase::typecheck::TypeError;
-use crate::phase::*;
+use crate::error::TypeError;
+use crate::phase::{Normalized, Type, Typed};
use crate::traits::StaticType;
use std::borrow::Cow;