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 --- CHANGELOG.md | 1 + dhall-lang | 2 +- dhall/src/semantics/tck/typecheck.rs | 20 +++++--------------- dhall/tests/type-inference/failure/mixedUnions.txt | 6 ------ .../failure/unit/RecordMixedKinds3.txt | 6 ------ .../unit/RightBiasedRecordMergeMixedKinds2.txt | 6 ------ .../unit/RightBiasedRecordMergeMixedKinds3.txt | 6 ------ .../failure/unit/UnionTypeMixedKinds.txt | 6 ------ .../failure/unit/UnionTypeMixedKinds2.txt | 6 ------ .../failure/unit/UnionTypeMixedKinds3.txt | 6 ------ tests_buffer | 1 - 11 files changed, 7 insertions(+), 59 deletions(-) delete mode 100644 dhall/tests/type-inference/failure/mixedUnions.txt delete mode 100644 dhall/tests/type-inference/failure/unit/RecordMixedKinds3.txt delete mode 100644 dhall/tests/type-inference/failure/unit/RightBiasedRecordMergeMixedKinds2.txt delete mode 100644 dhall/tests/type-inference/failure/unit/RightBiasedRecordMergeMixedKinds3.txt delete mode 100644 dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds.txt delete mode 100644 dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds2.txt delete mode 100644 dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds3.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 23997c5..9ac4b21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ #### [Unreleased] +- Allow unions with mixed kinds - Adjust precedence of `===` and `with` - Fix running tests on Windows. Developing on this lib should now be possible on Windows. diff --git a/dhall-lang b/dhall-lang index b788d6d..5973964 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit b788d6dd2150eec49b6bdd0cc7de50e403fad889 +Subproject commit 5973964062be2e7ea6ff7300a46616086dd9143b 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)?, diff --git a/dhall/tests/type-inference/failure/mixedUnions.txt b/dhall/tests/type-inference/failure/mixedUnions.txt deleted file mode 100644 index 2b307d0..0000000 --- a/dhall/tests/type-inference/failure/mixedUnions.txt +++ /dev/null @@ -1,6 +0,0 @@ -Type error: error: InvalidVariantType - --> :1:28 - | -1 | < Left : Natural | Right : Type > - | ^^^^ InvalidVariantType - | diff --git a/dhall/tests/type-inference/failure/unit/RecordMixedKinds3.txt b/dhall/tests/type-inference/failure/unit/RecordMixedKinds3.txt deleted file mode 100644 index a83bb4f..0000000 --- a/dhall/tests/type-inference/failure/unit/RecordMixedKinds3.txt +++ /dev/null @@ -1,6 +0,0 @@ -Type error: error: InvalidFieldType - --> :1:17 - | -1 | { x = Type, y = Kind } - | ^^^^ InvalidFieldType - | diff --git a/dhall/tests/type-inference/failure/unit/RightBiasedRecordMergeMixedKinds2.txt b/dhall/tests/type-inference/failure/unit/RightBiasedRecordMergeMixedKinds2.txt deleted file mode 100644 index 6a6da80..0000000 --- a/dhall/tests/type-inference/failure/unit/RightBiasedRecordMergeMixedKinds2.txt +++ /dev/null @@ -1,6 +0,0 @@ -Type error: error: InvalidFieldType - --> :1:22 - | -1 | { x = Bool } ⫽ { x = Kind } - | ^^^^ InvalidFieldType - | diff --git a/dhall/tests/type-inference/failure/unit/RightBiasedRecordMergeMixedKinds3.txt b/dhall/tests/type-inference/failure/unit/RightBiasedRecordMergeMixedKinds3.txt deleted file mode 100644 index 322e7f4..0000000 --- a/dhall/tests/type-inference/failure/unit/RightBiasedRecordMergeMixedKinds3.txt +++ /dev/null @@ -1,6 +0,0 @@ -Type error: error: InvalidFieldType - --> :1:21 - | -1 | { x = {=} } ⫽ { x = Kind } - | ^^^^ InvalidFieldType - | diff --git a/dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds.txt b/dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds.txt deleted file mode 100644 index ae6c845..0000000 --- a/dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds.txt +++ /dev/null @@ -1,6 +0,0 @@ -Type error: error: InvalidVariantType - --> :1:18 - | -1 | < x : Bool | y : Type > - | ^^^^ InvalidVariantType - | diff --git a/dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds2.txt b/dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds2.txt deleted file mode 100644 index faf81a9..0000000 --- a/dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds2.txt +++ /dev/null @@ -1,6 +0,0 @@ -Type error: error: InvalidVariantType - --> :1:18 - | -1 | < x : Kind | y : Type > - | ^^^^ InvalidVariantType - | diff --git a/dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds3.txt b/dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds3.txt deleted file mode 100644 index bbfb1f3..0000000 --- a/dhall/tests/type-inference/failure/unit/UnionTypeMixedKinds3.txt +++ /dev/null @@ -1,6 +0,0 @@ -Type error: error: InvalidVariantType - --> :1:18 - | -1 | < x : Kind | y : Bool > - | ^^^^ InvalidVariantType - | diff --git a/tests_buffer b/tests_buffer index e01d7a7..80fa833 100644 --- a/tests_buffer +++ b/tests_buffer @@ -35,6 +35,5 @@ failure/ merge { x = True, y = 1 } < x | y >.x merge {x=...,y=...} .x merge {x=...,y=...} .x -fix unit_RightBiasedRecordMergeMixedKinds3 & 2 & unit_RecordMixedKinds3 equivalence: -- cgit v1.2.3