diff options
| author | Nadrieril | 2019-04-10 22:32:07 +0200 | 
|---|---|---|
| committer | Nadrieril | 2019-04-10 22:32:07 +0200 | 
| commit | 7740ec004c6d7e073358bf2be00b6c0006e4dd06 (patch) | |
| tree | 8c7658d71fc0fcc5158ffe028bb6a9c10701f150 /dhall | |
| parent | 88ac184e7e967c4a5e257c91598f647b8294d71c (diff) | |
Allow providing type for typechecking in API
Diffstat (limited to 'dhall')
| -rw-r--r-- | dhall/src/imports.rs | 6 | ||||
| -rw-r--r-- | dhall/src/tests.rs | 23 | ||||
| -rw-r--r-- | dhall/src/traits/deserialize.rs | 7 | ||||
| -rw-r--r-- | dhall/src/typecheck.rs | 5 | 
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) | 
