diff options
author | sheaf <sam.derbyshire@gmail.com> | 2021-11-17 15:23:15 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-11-25 05:02:39 -0500 |
commit | f27a63fe12c60e6d6ec52e286dd0a0980eae206d (patch) | |
tree | 7605b1f07f678d4d64b4b895a86cf59e3bddaf4e /testsuite | |
parent | b52a9a3fa3caf6672fa8c04ac3bd1df353af44cf (diff) | |
download | haskell-f27a63fe12c60e6d6ec52e286dd0a0980eae206d.tar.gz |
Allow boring class declarations in hs-boot files
There are two different ways of declaring a class in an hs-boot file:
- a full declaration, where everything is written as it is
in the .hs file,
- an abstract declaration, where class methods and superclasses
are left out.
However, a declaration with no methods and a trivial superclass,
such as:
class () => C a
was erroneously considered to be an abstract declaration, because
the superclass is trivial.
This is remedied by a one line fix in GHC.Tc.TyCl.tcClassDecl1.
This patch also further clarifies the documentation around
class declarations in hs-boot files.
Fixes #20661, #20588.
Diffstat (limited to 'testsuite')
12 files changed, 92 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_compile/T20588d.hs b/testsuite/tests/typecheck/should_compile/T20588d.hs new file mode 100644 index 0000000000..fd2ab2a3c8 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20588d.hs @@ -0,0 +1,15 @@ + +{-# LANGUAGE TypeFamilies #-} + +module T20588d where + +import Data.Kind + +class C (a :: Type) where + {-# MINIMAL meth #-} + meth :: a -> a + meth = id + +class D (a :: Type) where + type family T a :: Type + type instance T a = Int diff --git a/testsuite/tests/typecheck/should_compile/T20588d.hs-boot b/testsuite/tests/typecheck/should_compile/T20588d.hs-boot new file mode 100644 index 0000000000..fd2ab2a3c8 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20588d.hs-boot @@ -0,0 +1,15 @@ + +{-# LANGUAGE TypeFamilies #-} + +module T20588d where + +import Data.Kind + +class C (a :: Type) where + {-# MINIMAL meth #-} + meth :: a -> a + meth = id + +class D (a :: Type) where + type family T a :: Type + type instance T a = Int diff --git a/testsuite/tests/typecheck/should_compile/T20588d_aux.hs b/testsuite/tests/typecheck/should_compile/T20588d_aux.hs new file mode 100644 index 0000000000..8065767a55 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20588d_aux.hs @@ -0,0 +1,4 @@ +module T20588d_aux where + +import {-# SOURCE #-} T20588d + diff --git a/testsuite/tests/typecheck/should_compile/T20661.hs b/testsuite/tests/typecheck/should_compile/T20661.hs new file mode 100644 index 0000000000..32be5ae52f --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20661.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE FunctionalDependencies #-} + +module T20661 where + +class C a b | a -> b diff --git a/testsuite/tests/typecheck/should_compile/T20661.hs-boot b/testsuite/tests/typecheck/should_compile/T20661.hs-boot new file mode 100644 index 0000000000..906d11fc08 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20661.hs-boot @@ -0,0 +1,7 @@ +{-# LANGUAGE FunctionalDependencies #-} + +module T20661 where + +-- Use an empty context to signify that this is not +-- an abstract class, but a class with no methods. +class () => C a b | a -> b diff --git a/testsuite/tests/typecheck/should_compile/T20661_aux.hs b/testsuite/tests/typecheck/should_compile/T20661_aux.hs new file mode 100644 index 0000000000..c50a5bdb49 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20661_aux.hs @@ -0,0 +1,7 @@ +{-# LANGUAGE FunctionalDependencies #-} + +module T20661_aux where + +import {-# SOURCE #-} T20661 + +instance C Int Bool diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T index d5faf615b4..74fa4f0da8 100644 --- a/testsuite/tests/typecheck/should_compile/all.T +++ b/testsuite/tests/typecheck/should_compile/all.T @@ -805,3 +805,5 @@ test('T20356', normal, compile, ['']) test('T20584', normal, compile, ['']) 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']) diff --git a/testsuite/tests/typecheck/should_fail/T20588c.hs b/testsuite/tests/typecheck/should_fail/T20588c.hs new file mode 100644 index 0000000000..1ebf815de2 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T20588c.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE DefaultSignatures #-} + +module T20588c where + +import Data.Kind + +class C (a :: Type) where + meth :: a + default meth :: Monoid a => a + meth = mempty diff --git a/testsuite/tests/typecheck/should_fail/T20588c.hs-boot b/testsuite/tests/typecheck/should_fail/T20588c.hs-boot new file mode 100644 index 0000000000..43c1625da1 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T20588c.hs-boot @@ -0,0 +1,8 @@ +{-# LANGUAGE DefaultSignatures #-} + +module T20588c where + +import Data.Kind + +class C (a :: Type) where + meth :: a diff --git a/testsuite/tests/typecheck/should_fail/T20588c.stderr b/testsuite/tests/typecheck/should_fail/T20588c.stderr new file mode 100644 index 0000000000..d15573a30f --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T20588c.stderr @@ -0,0 +1,14 @@ + +T20588c.hs-boot:7:1: error: + Class ‘C’ has conflicting definitions in the module + and its hs-boot file + Main module: type C :: * -> Constraint + class C a where + meth :: a + default meth :: Monoid a => a + Boot file: type C :: * -> Constraint + class C a where + meth :: a + {-# MINIMAL meth #-} + The methods do not match: + The default methods associated with ‘meth’ are different diff --git a/testsuite/tests/typecheck/should_fail/T20588c_aux.hs b/testsuite/tests/typecheck/should_fail/T20588c_aux.hs new file mode 100644 index 0000000000..f1c01164a7 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T20588c_aux.hs @@ -0,0 +1,4 @@ +module T20588c_aux where + +import {-# SOURCE #-} T20588c + diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T index bba77ee675..18b07edc87 100644 --- a/testsuite/tests/typecheck/should_fail/all.T +++ b/testsuite/tests/typecheck/should_fail/all.T @@ -626,3 +626,4 @@ test('T20260', normal, compile_fail, ['']) test('OrdErr', normal, compile_fail, ['']) 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']) |