From 845abbb0404ac15cefeca8b6ac32d9b3f93e5987 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 21 Mar 2019 16:36:46 +0100 Subject: Represent Optional literals more faithfully --- dhall/src/typecheck.rs | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) (limited to 'dhall/src/typecheck.rs') 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> = 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> = 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) => { -- cgit v1.2.3