diff options
author | sheaf <sam.derbyshire@gmail.com> | 2022-02-07 10:10:10 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-02-08 05:28:05 -0500 |
commit | 6d77d3d8d6cedb840e1a86a3b23d6e6c1409ccbd (patch) | |
tree | 8b77d568b0908f62ae94f802823db5fed5aa27f5 /testsuite/tests/typecheck | |
parent | a9355e84480e421a22fee57d6ee24d9ec059e128 (diff) | |
download | haskell-6d77d3d8d6cedb840e1a86a3b23d6e6c1409ccbd.tar.gz |
Relax TyEq:N: allow out-of-scope newtype DataCon
The 'bad_newtype' assertion in GHC.Tc.Solver.Canonical.canEqCanLHSFinish
failed to account for the possibility that the newtype constructor
might not be in scope, in which case we don't provide any guarantees
about canonicalising away a newtype on the RHS of a representational
equality.
Fixes #21010
Diffstat (limited to 'testsuite/tests/typecheck')
-rw-r--r-- | testsuite/tests/typecheck/should_compile/T21010.hs | 12 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_compile/T21010A.hs | 15 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_compile/T21010B.hs | 21 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_compile/all.T | 1 |
4 files changed, 49 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_compile/T21010.hs b/testsuite/tests/typecheck/should_compile/T21010.hs new file mode 100644 index 0000000000..249d0f12c0 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T21010.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE Haskell2010 #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE TypeFamilies #-} + +module T21010 ( CBind(..) ) where +import T21010A ( WrapMono, Constrained(Dom), withMonoCoercible ) + +class CBind m where + (>>-) :: (Dom m a, Dom m b) => m a -> (a -> m b) -> m b + +instance CBind (WrapMono ()) where + (>>-) = withMonoCoercible undefined diff --git a/testsuite/tests/typecheck/should_compile/T21010A.hs b/testsuite/tests/typecheck/should_compile/T21010A.hs new file mode 100644 index 0000000000..234e1c72d7 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T21010A.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE Haskell2010 #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE TypeFamilies #-} + +module T21010A ( WrapMono, Constrained(..), withMonoCoercible ) where +import T21010B ( WrapMono(..), withMonoCoercible ) + +import Data.Kind ( Type, Constraint ) + +class Constrained (f :: Type -> Type) where + type Dom f (a :: Type) :: Constraint + +instance Constrained (WrapMono mono) where + type Dom (WrapMono mono) b = b ~ mono diff --git a/testsuite/tests/typecheck/should_compile/T21010B.hs b/testsuite/tests/typecheck/should_compile/T21010B.hs new file mode 100644 index 0000000000..2a19a7e7e7 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T21010B.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE Haskell2010 #-} +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE RoleAnnotations #-} +{-# LANGUAGE TypeFamilies #-} + +module T21010B where +import Data.Coerce ( Coercible) +import Data.Kind ( Constraint, Type ) + +newtype WrapFunctor f (a :: Type) = WrapFunctor {runFunctor :: f a} + +type role WrapMono representational phantom +newtype WrapMono mono b = WrapMono mono + +withMonoCoercible + :: (Coercible (WrapMono mono other) mono => r) + -> r +withMonoCoercible = \x -> x diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T index ef13910c41..39878e3ce6 100644 --- a/testsuite/tests/typecheck/should_compile/all.T +++ b/testsuite/tests/typecheck/should_compile/all.T @@ -810,3 +810,4 @@ test('StaticPtrTypeFamily', normal, compile, ['']) test('T20946', normal, compile, ['']) test('T20996', normal, compile, ['']) test('T20732', normal, compile, ['']) +test('T21010', [extra_files(['T21010A.hs', 'T21010B.hs'])], multimod_compile, ['T21010.hs', '-v0']) |