summaryrefslogtreecommitdiff
path: root/serde_dhall/src/options
diff options
context:
space:
mode:
authorNadrieril2020-12-08 18:47:41 +0000
committerGitHub2020-12-08 18:47:41 +0000
commit109dcf894e759bce1c28f9ae94f3fdaa6e08feb5 (patch)
tree9ce374d02ea15966c7bb2dfb39d5d81720a63687 /serde_dhall/src/options
parent35ed301e8de5a2b1102e370e638564d3c3d204a8 (diff)
parentd0a61179addf838d33e7e7a4c6a13f06e871e9c5 (diff)
Merge pull request #204 from Nadrieril/source-id
Diffstat (limited to 'serde_dhall/src/options')
-rw-r--r--serde_dhall/src/options/de.rs42
1 files changed, 24 insertions, 18 deletions
diff --git a/serde_dhall/src/options/de.rs b/serde_dhall/src/options/de.rs
index 22fa7ba..30846a2 100644
--- a/serde_dhall/src/options/de.rs
+++ b/serde_dhall/src/options/de.rs
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};
-use dhall::Parsed;
+use dhall::{Ctxt, Parsed};
use crate::options::{HasAnnot, ManualAnnot, NoAnnot, StaticAnnot, TypeAnnot};
use crate::SimpleType;
@@ -229,26 +229,32 @@ impl<'a, A> Deserializer<'a, A> {
// self
// }
- fn _parse<T>(&self) -> dhall::error::Result<Value>
+ fn _parse<T>(&self) -> dhall::error::Result<Result<Value>>
where
A: TypeAnnot,
T: HasAnnot<A>,
{
- let parsed = match &self.source {
- Source::Str(s) => Parsed::parse_str(s)?,
- Source::File(p) => Parsed::parse_file(p.as_ref())?,
- Source::BinaryFile(p) => Parsed::parse_binary_file(p.as_ref())?,
- };
- let resolved = if self.allow_imports {
- parsed.resolve()?
- } else {
- parsed.skip_resolve()?
- };
- let typed = match &T::get_annot(self.annot) {
- None => resolved.typecheck()?,
- Some(ty) => resolved.typecheck_with(ty.to_value().as_hir())?,
- };
- Ok(Value::from_nir(typed.normalize().as_nir()))
+ Ctxt::with_new(|cx| {
+ let parsed = match &self.source {
+ Source::Str(s) => Parsed::parse_str(s)?,
+ Source::File(p) => Parsed::parse_file(p.as_ref())?,
+ Source::BinaryFile(p) => Parsed::parse_binary_file(p.as_ref())?,
+ };
+ let resolved = if self.allow_imports {
+ parsed.resolve(cx)?
+ } else {
+ parsed.skip_resolve(cx)?
+ };
+ let typed = match &T::get_annot(self.annot) {
+ None => resolved.typecheck(cx)?,
+ Some(ty) => resolved.typecheck_with(cx, &ty.to_hir())?,
+ };
+ Ok(Value::from_nir_and_ty(
+ cx,
+ typed.normalize(cx).as_nir(),
+ typed.ty().as_nir(),
+ ))
+ })
}
/// Parses the chosen dhall value with the options provided.
@@ -274,7 +280,7 @@ impl<'a, A> Deserializer<'a, A> {
let val = self
._parse::<T>()
.map_err(ErrorKind::Dhall)
- .map_err(Error)?;
+ .map_err(Error)??;
T::from_dhall(&val)
}
}