diff options
author | sheaf <sam.derbyshire@gmail.com> | 2022-01-10 12:30:27 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-01-11 19:41:28 -0500 |
commit | addf8e544841a3f7c818331e47fa89a2cbfb7b29 (patch) | |
tree | 39c9975cbefcdaba64d09bf236f100948ed5f129 /testsuite/tests | |
parent | c6300cb319f5d756e4addf8193b8115949e645ac (diff) | |
download | haskell-addf8e544841a3f7c818331e47fa89a2cbfb7b29.tar.gz |
Kind TyCons: require KindSignatures, not DataKinds
Uses of a TyCon in a kind signature required users to enable
DataKinds, which didn't make much sense, e.g. in
type U = Type
type MyMaybe (a :: U) = MyNothing | MyJust a
Now the DataKinds error is restricted to data constructors;
the use of kind-level type constructors is instead gated behind
-XKindSignatures.
This patch also adds a convenience pattern synonym for patching
on both a TyCon or a TcTyCon stored in a TcTyThing, used in
tcTyVar and tc_infer_id.
fixes #20873
Diffstat (limited to 'testsuite/tests')
7 files changed, 61 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_compile/T20873.hs b/testsuite/tests/typecheck/should_compile/T20873.hs new file mode 100644 index 0000000000..825b12aece --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20873.hs @@ -0,0 +1,23 @@ + +{-# LANGUAGE GADTSyntax, StandaloneKindSignatures, NoDataKinds #-} + +module T20873 where + +import Data.Kind ( Type ) + +type U a = Type +type V a = a + +type MyMaybe1 :: U Type -> U Type +data MyMaybe1 a = MyJust1 a | MyNothing1 + +type MyMaybe2 :: V Type -> V Type +data MyMaybe2 a = MyJust2 a | MyNothing2 + +data MyMaybe3 (a :: U Type) :: U Type where + MyJust3 :: a -> MyMaybe3 a + MyNothing3 :: MyMaybe3 a + +data MyMaybe4 (a :: V Type) :: V Type where + MyJust4 :: a -> MyMaybe4 a + MyNothing4 :: MyMaybe4 a diff --git a/testsuite/tests/typecheck/should_compile/T20873b.hs b/testsuite/tests/typecheck/should_compile/T20873b.hs new file mode 100644 index 0000000000..5abe5942a7 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20873b.hs @@ -0,0 +1,11 @@ + +{-# LANGUAGE NoDataKinds #-} + +module T20873b where + +import T20873b_aux (P) + +type Q = P + -- P = 'MkA is a promoted data constructor, + -- but we should still allow users to use P with -XNoDataKinds, + -- to avoid implementation details of M1 leaking. diff --git a/testsuite/tests/typecheck/should_compile/T20873b_aux.hs b/testsuite/tests/typecheck/should_compile/T20873b_aux.hs new file mode 100644 index 0000000000..efd498471a --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20873b_aux.hs @@ -0,0 +1,7 @@ + +{-# LANGUAGE DataKinds #-} + +module T20873b_aux where + +data A = MkA +type P = 'MkA diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T index a3c89c0ab0..8b31c8b3cc 100644 --- a/testsuite/tests/typecheck/should_compile/all.T +++ b/testsuite/tests/typecheck/should_compile/all.T @@ -804,3 +804,6 @@ test('T20584b', normal, compile, ['']) test('T20588b', [extra_files(['T20588b.hs', 'T20588b.hs-boot', 'T20588b_aux.hs'])], multimod_compile, ['T20588b_aux.hs', '-v0']) test('T20588d', [extra_files(['T20588d.hs', 'T20588d.hs-boot', 'T20588d_aux.hs'])], multimod_compile, ['T20588d_aux.hs', '-v0']) test('T20661', [extra_files(['T20661.hs', 'T20661.hs-boot', 'T20661_aux.hs'])], multimod_compile, ['T20661_aux.hs', '-v0']) + +test('T20873', normal, compile, ['']) +test('T20873b', [extra_files(['T20873b_aux.hs'])], multimod_compile, ['T20873b', '-v0']) diff --git a/testsuite/tests/typecheck/should_fail/T20873c.hs b/testsuite/tests/typecheck/should_fail/T20873c.hs new file mode 100644 index 0000000000..776c061f13 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T20873c.hs @@ -0,0 +1,11 @@ + +{-# LANGUAGE GADTSyntax, NoKindSignatures, NoDataKinds #-} + +module T20873c where + +import Data.Kind ( Type ) + +type U a = Type + +data Foo :: U Int where + MkFoo :: Foo diff --git a/testsuite/tests/typecheck/should_fail/T20873c.stderr b/testsuite/tests/typecheck/should_fail/T20873c.stderr new file mode 100644 index 0000000000..972d01c583 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T20873c.stderr @@ -0,0 +1,5 @@ + +T20873c.hs:10:1: error: + • Illegal kind signature ‘Foo’ + (Use KindSignatures to allow kind signatures) + • In the data declaration for ‘Foo’ diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T index 908edcfe27..ff092df478 100644 --- a/testsuite/tests/typecheck/should_fail/all.T +++ b/testsuite/tests/typecheck/should_fail/all.T @@ -628,3 +628,4 @@ test('T20542', normal, compile_fail, ['']) test('T20588', [extra_files(['T20588.hs', 'T20588.hs-boot', 'T20588_aux.hs'])], multimod_compile_fail, ['T20588_aux.hs', '-v0']) test('T20588c', [extra_files(['T20588c.hs', 'T20588c.hs-boot', 'T20588c_aux.hs'])], multimod_compile_fail, ['T20588c_aux.hs', '-v0']) test('T20189', normal, compile_fail, ['']) +test('T20873c', normal, compile_fail, ['']) |