summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
Diffstat (limited to 'dhall/src')
-rw-r--r--dhall/src/imports.rs6
-rw-r--r--dhall/src/tests.rs23
-rw-r--r--dhall/src/traits/deserialize.rs7
-rw-r--r--dhall/src/typecheck.rs5
4 files changed, 21 insertions, 20 deletions
diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs
index cedc072..7810c55 100644
--- a/dhall/src/imports.rs
+++ b/dhall/src/imports.rs
@@ -97,9 +97,3 @@ impl Parsed {
crate::imports::resolve_expr(self, false)
}
}
-
-// Deprecated, used for tests only
-#[allow(dead_code)]
-pub fn load_dhall_file(f: &Path) -> Result<SubExpr<X, X>, Error> {
- Ok(load_import(f)?.0)
-}
diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs
index dede639..6b1c426 100644
--- a/dhall/src/tests.rs
+++ b/dhall/src/tests.rs
@@ -31,9 +31,6 @@ macro_rules! make_spec_test {
use crate::error::{Error, Result};
use crate::expr::Parsed;
-use crate::*;
-use dhall_core::*;
-use dhall_generator as dhall;
use std::path::PathBuf;
#[allow(dead_code)]
@@ -47,11 +44,6 @@ pub enum Feature {
TypeInferenceFailure,
}
-// Deprecated
-fn read_dhall_file<'i>(file_path: &str) -> Result<SubExpr<X, X>> {
- crate::imports::load_dhall_file(&PathBuf::from(file_path))
-}
-
fn parse_file_str<'i>(file_path: &str) -> Result<Parsed> {
Parsed::parse_file(&PathBuf::from(file_path))
}
@@ -134,11 +126,18 @@ pub fn run_test(base_path: &str, feature: Feature) {
.spawn(|| {
let expr_file_path = base_path.clone() + "A.dhall";
let expected_file_path = base_path + "B.dhall";
- let expr = read_dhall_file(&expr_file_path).unwrap();
- let expected =
- read_dhall_file(&expected_file_path).unwrap();
- typecheck::type_of(dhall::subexpr!(expr: expected))
+ let expr = parse_file_str(&expr_file_path)
+ .unwrap()
+ .resolve()
.unwrap();
+ let expected = parse_file_str(&expected_file_path)
+ .unwrap()
+ .resolve()
+ .unwrap()
+ .skip_typecheck()
+ .skip_normalize()
+ .into_type();
+ expr.typecheck_with(&expected).unwrap();
})
.unwrap()
.join()
diff --git a/dhall/src/traits/deserialize.rs b/dhall/src/traits/deserialize.rs
index ad4cde6..5271a65 100644
--- a/dhall/src/traits/deserialize.rs
+++ b/dhall/src/traits/deserialize.rs
@@ -24,8 +24,11 @@ impl<'a> Deserialize<'a> for Resolved {
impl<'a> Deserialize<'a> for Typed {
/// Parses, resolves and typechecks the provided string.
fn from_str(s: &'a str, ty: Option<&Type>) -> Result<Self> {
- // TODO: compare with provided type
- Ok(Resolved::from_str(s, ty)?.typecheck()?)
+ let resolved = Resolved::from_str(s, ty)?;
+ match ty {
+ None => Ok(resolved.typecheck()?),
+ Some(t) => Ok(resolved.typecheck_with(t)?),
+ }
}
}
diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs
index f51f1b6..9741e65 100644
--- a/dhall/src/typecheck.rs
+++ b/dhall/src/typecheck.rs
@@ -13,6 +13,11 @@ impl Resolved {
pub fn typecheck(self) -> Result<Typed, TypeError<X>> {
type_of(self.0.clone())
}
+ pub fn typecheck_with(self, ty: &Type) -> Result<Typed, TypeError<X>> {
+ let expr: SubExpr<_, _> = self.0.clone();
+ let ty: SubExpr<_, _> = ty.as_normalized()?.as_expr().clone();
+ type_of(dhall::subexpr!(expr: ty))
+ }
/// Pretends this expression has been typechecked. Use with care.
pub fn skip_typecheck(self) -> Typed {
Typed(self.0, UNTYPE)