From 9da112a1985124f549254943c81495e637fb43cc Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 11 Apr 2020 22:05:00 +0100 Subject: spec: allow unions with mixed kinds --- dhall/src/semantics/tck/typecheck.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'dhall/src/semantics') diff --git a/dhall/src/semantics/tck/typecheck.rs b/dhall/src/semantics/tck/typecheck.rs index 361e1b4..d21c7ce 100644 --- a/dhall/src/semantics/tck/typecheck.rs +++ b/dhall/src/semantics/tck/typecheck.rs @@ -137,30 +137,20 @@ fn type_one_layer( Type::from_const(k) } ExprKind::UnionType(kts) => { - // Check that all types are the same const - let mut k = None; + // An empty union type has type Type; + // an union type with only unary variants also has type Type + let mut k = Const::Type; for t in kts.values() { if let Some(t) = t { - let c = match t.ty().as_const() { - Some(c) => c, + match t.ty().as_const() { + Some(c) => k = max(k, c), None => { return mk_span_err(t.span(), "InvalidVariantType") } - }; - match k { - None => k = Some(c), - Some(k) if k == c => {} - _ => { - return mk_span_err(t.span(), "InvalidVariantType") - } } } } - // An empty union type has type Type; - // an union type with only unary variants also has type Type - let k = k.unwrap_or(Const::Type); - Type::from_const(k) } ExprKind::Op(op) => typecheck_operation(env, span, op)?, -- cgit v1.2.3