summaryrefslogtreecommitdiff
path: root/dhall/src/error
diff options
context:
space:
mode:
authorNadrieril Feneanar2020-01-31 20:22:09 +0000
committerGitHub2020-01-31 20:22:09 +0000
commit72a6fef65bb3d34be1f501a1f6de66fb8a54fa04 (patch)
tree033314a3e3254e8fcf1154d1570a720b058db4d9 /dhall/src/error
parent140b5d5ab24795a4053f7e5bdcd8b2343e35558e (diff)
parent0c0e7d4db15abf709fafc0c9b9db4d377ea3c158 (diff)
Rewrite normalization and typechecking with environments (#126)
Rewrite normalization and typechecking with environments
Diffstat (limited to '')
-rw-r--r--dhall/src/error/mod.rs126
1 files changed, 60 insertions, 66 deletions
diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs
index 6e7be64..4df018d 100644
--- a/dhall/src/error/mod.rs
+++ b/dhall/src/error/mod.rs
@@ -1,10 +1,9 @@
use std::io::Error as IOError;
-use crate::semantics::core::context::TypecheckContext;
-use crate::semantics::core::value::Value;
-use crate::semantics::phase::resolve::ImportStack;
-use crate::semantics::phase::NormalizedExpr;
-use crate::syntax::{BinOp, Import, Label, ParseError, Span};
+use crate::semantics::resolve::ImportStack;
+use crate::semantics::Value;
+use crate::syntax::{Import, ParseError};
+use crate::NormalizedExpr;
pub type Result<T> = std::result::Result<T, Error>;
@@ -37,65 +36,59 @@ pub enum EncodeError {
CBORError(serde_cbor::error::Error),
}
-/// A structured type error that includes context
+/// A structured type error
#[derive(Debug)]
pub struct TypeError {
message: TypeMessage,
- context: TypecheckContext,
}
/// The specific type error
#[derive(Debug)]
pub(crate) enum TypeMessage {
- UnboundVariable(Span),
+ // UnboundVariable(Span),
InvalidInputType(Value),
InvalidOutputType(Value),
- NotAFunction(Value),
- TypeMismatch(Value, Value, Value),
- AnnotMismatch(Value, Value),
- InvalidListElement(usize, Value, Value),
- InvalidListType(Value),
- InvalidOptionalType(Value),
- InvalidPredicate(Value),
- IfBranchMismatch(Value, Value),
- IfBranchMustBeTerm(bool, Value),
- InvalidFieldType(Label, Value),
- NotARecord(Label, Value),
- MustCombineRecord(Value),
- MissingRecordField(Label, Value),
- MissingUnionField(Label, Value),
- BinOpTypeMismatch(BinOp, Value),
- InvalidTextInterpolation(Value),
- Merge1ArgMustBeRecord(Value),
- Merge2ArgMustBeUnionOrOptional(Value),
- MergeEmptyNeedsAnnotation,
- MergeHandlerMissingVariant(Label),
- MergeVariantMissingHandler(Label),
- MergeAnnotMismatch,
- MergeHandlerTypeMismatch,
- MergeHandlerReturnTypeMustNotBeDependent,
- ProjectionMustBeRecord,
- ProjectionMissingEntry,
- ProjectionDuplicateField,
+ // NotAFunction(Value),
+ // TypeMismatch(Value, Value, Value),
+ // AnnotMismatch(Value, Value),
+ // InvalidListElement(usize, Value, Value),
+ // InvalidListType(Value),
+ // InvalidOptionalType(Value),
+ // InvalidPredicate(Value),
+ // IfBranchMismatch(Value, Value),
+ // IfBranchMustBeTerm(bool, Value),
+ // InvalidFieldType(Label, Value),
+ // NotARecord(Label, Value),
+ // MustCombineRecord(Value),
+ // MissingRecordField(Label, Value),
+ // MissingUnionField(Label, Value),
+ // BinOpTypeMismatch(BinOp, Value),
+ // InvalidTextInterpolation(Value),
+ // Merge1ArgMustBeRecord(Value),
+ // Merge2ArgMustBeUnionOrOptional(Value),
+ // MergeEmptyNeedsAnnotation,
+ // MergeHandlerMissingVariant(Label),
+ // MergeVariantMissingHandler(Label),
+ // MergeAnnotMismatch,
+ // MergeHandlerTypeMismatch,
+ // MergeHandlerReturnTypeMustNotBeDependent,
+ // ProjectionMustBeRecord,
+ // ProjectionMissingEntry,
+ // ProjectionDuplicateField,
Sort,
- RecordTypeDuplicateField,
- RecordTypeMergeRequiresRecordType(Value),
- UnionTypeDuplicateField,
- EquivalenceArgumentMustBeTerm(bool, Value),
- EquivalenceTypeMismatch(Value, Value),
- AssertMismatch(Value, Value),
- AssertMustTakeEquivalence,
+ // RecordTypeDuplicateField,
+ // RecordTypeMergeRequiresRecordType(Value),
+ // UnionTypeDuplicateField,
+ // EquivalenceArgumentMustBeTerm(bool, Value),
+ // EquivalenceTypeMismatch(Value, Value),
+ // AssertMismatch(Value, Value),
+ // AssertMustTakeEquivalence,
+ Custom(String),
}
impl TypeError {
- pub(crate) fn new(
- context: &TypecheckContext,
- message: TypeMessage,
- ) -> Self {
- TypeError {
- context: context.clone(),
- message,
- }
+ pub(crate) fn new(message: TypeMessage) -> Self {
+ TypeError { message }
}
}
@@ -103,28 +96,29 @@ impl std::fmt::Display for TypeError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use TypeMessage::*;
let msg = match &self.message {
- UnboundVariable(span) => span.error("Type error: Unbound variable"),
+ // UnboundVariable(var) => var.error("Type error: Unbound variable"),
InvalidInputType(v) => {
v.span().error("Type error: Invalid function input")
}
InvalidOutputType(v) => {
v.span().error("Type error: Invalid function output")
}
- NotAFunction(v) => v.span().error("Type error: Not a function"),
- TypeMismatch(x, y, z) => {
- x.span()
- .error("Type error: Wrong type of function argument")
- + "\n"
- + &z.span().error(format!(
- "This argument has type {:?}",
- z.get_type().unwrap()
- ))
- + "\n"
- + &y.span().error(format!(
- "But the function expected an argument of type {:?}",
- y
- ))
- }
+ // NotAFunction(v) => v.span().error("Type error: Not a function"),
+ // TypeMismatch(x, y, z) => {
+ // x.span()
+ // .error("Type error: Wrong type of function argument")
+ // + "\n"
+ // + &z.span().error(format!(
+ // "This argument has type {:?}",
+ // z.get_type().unwrap()
+ // ))
+ // + "\n"
+ // + &y.span().error(format!(
+ // "But the function expected an argument of type {:?}",
+ // y
+ // ))
+ // }
+ Custom(s) => format!("Type error: Unhandled error: {}", s),
_ => format!("Type error: Unhandled error: {:?}", self.message),
};
write!(f, "{}", msg)