summaryrefslogtreecommitdiff
path: root/dhall/src/typecheck.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-21 16:36:46 +0100
committerNadrieril2019-03-21 16:36:46 +0100
commit845abbb0404ac15cefeca8b6ac32d9b3f93e5987 (patch)
tree74a363bafddc951ae08fc722ab8d2f1891e57f28 /dhall/src/typecheck.rs
parent427c5e55a6e6768b22c3e7ad40594d451ac024e7 (diff)
Represent Optional literals more faithfully
Diffstat (limited to '')
-rw-r--r--dhall/src/typecheck.rs28
1 files changed, 8 insertions, 20 deletions
diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs
index 15fb344..32ffe0e 100644
--- a/dhall/src/typecheck.rs
+++ b/dhall/src/typecheck.rs
@@ -372,29 +372,17 @@ where
}
return Ok(dhall_expr!(List t));
}
- OptionalLit(t, xs) => {
- let mut iter = xs.iter();
- let t: Rc<Expr<_, _>> = match t {
- Some(t) => t.clone(),
- None => {
- let x = iter.next().unwrap();
- type_with(ctx, x.clone())?
- }
- };
-
+ EmptyOptionalLit(t) => {
+ let s = normalized_type_with(ctx, t.clone())?;
+ ensure_is_type(s, InvalidOptionalType(t.clone()))?;
+ let t = normalize(t.clone());
+ return Ok(dhall_expr!(Optional t));
+ }
+ NEOptionalLit(x) => {
+ let t: Rc<Expr<_, _>> = type_with(ctx, x.clone())?;
let s = normalized_type_with(ctx, t.clone())?;
ensure_is_type(s, InvalidOptionalType(t.clone()))?;
let t = normalize(t);
- for x in iter {
- let t2 = normalized_type_with(ctx, x.clone())?;
- if !prop_equal(t.as_ref(), t2.as_ref()) {
- return Err(mkerr(InvalidOptionalElement(
- t,
- x.clone(),
- t2,
- )));
- }
- }
return Ok(dhall_expr!(Optional t));
}
RecordType(kts) => {