diff options
Diffstat (limited to '')
12 files changed, 46 insertions, 18 deletions
diff --git a/dhall/src/core/value.rs b/dhall/src/core/value.rs index 61c7015..d4f5131 100644 --- a/dhall/src/core/value.rs +++ b/dhall/src/core/value.rs @@ -165,6 +165,9 @@ impl Value { _ => None, } } + pub(crate) fn span(&self) -> Span { + self.as_internal().span.clone() + } fn as_internal(&self) -> Ref<ValueInternal> { self.0.borrow() diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs index 02e8ed3..4d59cbb 100644 --- a/dhall/src/error/mod.rs +++ b/dhall/src/error/mod.rs @@ -104,16 +104,16 @@ impl std::fmt::Display for TypeError { use TypeMessage::*; let msg = match &self.message { UnboundVariable(span) => span.error("Type error: Unbound variable"), - InvalidInputType(_) => { - "Type error: Invalid function input".to_string() + InvalidInputType(v) => { + v.span().error("Type error: Invalid function input") } - InvalidOutputType(_) => { - "Type error: Invalid function output".to_string() - } - NotAFunction(_) => "Type error: Not a function".to_string(), - TypeMismatch(_, _, _) => { - "Type error: Wrong type of function argument".to_string() + InvalidOutputType(v) => { + v.span().error("Type error: Invalid function output") } + NotAFunction(v) => v.span().error("Type error: Not a function"), + TypeMismatch(v, _, _) => v + .span() + .error("Type error: Wrong type of function argument"), _ => "Type error: Unhandled error".to_string(), }; write!(f, "{}", msg) diff --git a/dhall/tests/type-errors/hurkensParadox.txt b/dhall/tests/type-errors/hurkensParadox.txt index ab75f15..69428b8 100644 --- a/dhall/tests/type-errors/hurkensParadox.txt +++ b/dhall/tests/type-errors/hurkensParadox.txt @@ -1 +1 @@ -Type error: Wrong type of function argument +[unknown location] Type error: Wrong type of function argument diff --git a/dhall/tests/type-errors/unit/FunctionApplicationArgumentNotMatch.txt b/dhall/tests/type-errors/unit/FunctionApplicationArgumentNotMatch.txt index ab75f15..69428b8 100644 --- a/dhall/tests/type-errors/unit/FunctionApplicationArgumentNotMatch.txt +++ b/dhall/tests/type-errors/unit/FunctionApplicationArgumentNotMatch.txt @@ -1 +1 @@ -Type error: Wrong type of function argument +[unknown location] Type error: Wrong type of function argument diff --git a/dhall/tests/type-errors/unit/FunctionApplicationIsNotFunction.txt b/dhall/tests/type-errors/unit/FunctionApplicationIsNotFunction.txt index 4757d2d..062f9de 100644 --- a/dhall/tests/type-errors/unit/FunctionApplicationIsNotFunction.txt +++ b/dhall/tests/type-errors/unit/FunctionApplicationIsNotFunction.txt @@ -1 +1,6 @@ -Type error: Not a function + --> 1:1 + | +1 | True True␊ + | ^--^ + | + = Type error: Not a function diff --git a/dhall/tests/type-errors/unit/FunctionArgumentTypeNotAType.txt b/dhall/tests/type-errors/unit/FunctionArgumentTypeNotAType.txt index faea460..9e43c33 100644 --- a/dhall/tests/type-errors/unit/FunctionArgumentTypeNotAType.txt +++ b/dhall/tests/type-errors/unit/FunctionArgumentTypeNotAType.txt @@ -1 +1,6 @@ -Type error: Invalid function input + --> 1:7 + | +1 | λ(_ : 1) → _␊ + | ^ + | + = Type error: Invalid function input diff --git a/dhall/tests/type-errors/unit/FunctionTypeArgumentTypeNotAType.txt b/dhall/tests/type-errors/unit/FunctionTypeArgumentTypeNotAType.txt index faea460..dd2e758 100644 --- a/dhall/tests/type-errors/unit/FunctionTypeArgumentTypeNotAType.txt +++ b/dhall/tests/type-errors/unit/FunctionTypeArgumentTypeNotAType.txt @@ -1 +1,6 @@ -Type error: Invalid function input + --> 1:1 + | +1 | 2 → _␊ + | ^ + | + = Type error: Invalid function input diff --git a/dhall/tests/type-errors/unit/ListLiteralEmptyNotType.txt b/dhall/tests/type-errors/unit/ListLiteralEmptyNotType.txt index ab75f15..bc5cc40 100644 --- a/dhall/tests/type-errors/unit/ListLiteralEmptyNotType.txt +++ b/dhall/tests/type-errors/unit/ListLiteralEmptyNotType.txt @@ -1 +1,6 @@ -Type error: Wrong type of function argument + --> 1:6 + | +1 | [] : List Type␊ + | ^--^ + | + = Type error: Wrong type of function argument diff --git a/dhall/tests/type-errors/unit/MergeHandlerNotFunction.txt b/dhall/tests/type-errors/unit/MergeHandlerNotFunction.txt index 4757d2d..c5ed223 100644 --- a/dhall/tests/type-errors/unit/MergeHandlerNotFunction.txt +++ b/dhall/tests/type-errors/unit/MergeHandlerNotFunction.txt @@ -1 +1 @@ -Type error: Not a function +[unknown location] Type error: Not a function diff --git a/dhall/tests/type-errors/unit/MergeHandlerNotMatchAlternativeType.txt b/dhall/tests/type-errors/unit/MergeHandlerNotMatchAlternativeType.txt index ab75f15..69428b8 100644 --- a/dhall/tests/type-errors/unit/MergeHandlerNotMatchAlternativeType.txt +++ b/dhall/tests/type-errors/unit/MergeHandlerNotMatchAlternativeType.txt @@ -1 +1 @@ -Type error: Wrong type of function argument +[unknown location] Type error: Wrong type of function argument diff --git a/dhall/tests/type-errors/unit/NaturalSubtractNotNatural.txt b/dhall/tests/type-errors/unit/NaturalSubtractNotNatural.txt index ab75f15..fd906bf 100644 --- a/dhall/tests/type-errors/unit/NaturalSubtractNotNatural.txt +++ b/dhall/tests/type-errors/unit/NaturalSubtractNotNatural.txt @@ -1 +1,6 @@ -Type error: Wrong type of function argument + --> 1:1 + | +1 | Natural/subtract True True␊ + | ^--------------^ + | + = Type error: Wrong type of function argument diff --git a/dhall_syntax/src/core/span.rs b/dhall_syntax/src/core/span.rs index 4012cfb..d63a619 100644 --- a/dhall_syntax/src/core/span.rs +++ b/dhall_syntax/src/core/span.rs @@ -69,7 +69,7 @@ impl Span { let message: String = message.into(); let span = match self { self::Span::Parsed(span) => span, - _ => return format!("Unknown location: {}", message), + _ => return format!("[unknown location] {}", message), }; let span = Span::new(&*span.input, span.start, span.end).unwrap(); let err: ErrorVariant<!> = ErrorVariant::CustomError { message }; |