diff options
author | Jakob Brünker <jakob.bruenker@gmail.com> | 2021-06-26 14:19:29 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-06-27 06:15:11 -0400 |
commit | 3e71874b32725cb0bd95f6a7effc77190a860b3e (patch) | |
tree | a36430a7c277e713e4fb2f25b24f526be499efe4 | |
parent | b1792fefaf61099541157aaf77a6835ab7a09958 (diff) | |
download | haskell-3e71874b32725cb0bd95f6a7effc77190a860b3e.tar.gz |
Tc: Allow Typeable in quantified constraints
Previously, when using Typeable in a quantified constraint, GHC would
complain that user-specified instances of Typeable aren't allowed. This
was because checking for SigmaCtxt was missing from a check for whether
an instance head is a hand-written binding.
Fixes #20033
-rw-r--r-- | compiler/GHC/Tc/Validity.hs | 1 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_compile/T20033.hs | 17 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_compile/all.T | 1 |
3 files changed, 19 insertions, 0 deletions
diff --git a/compiler/GHC/Tc/Validity.hs b/compiler/GHC/Tc/Validity.hs index 41e1a1c5a9..3c664cb06e 100644 --- a/compiler/GHC/Tc/Validity.hs +++ b/compiler/GHC/Tc/Validity.hs @@ -1586,6 +1586,7 @@ check_special_inst_head dflags is_boot is_sig ctxt clas cls_args InstDeclCtxt stand_alone -> not stand_alone SpecInstCtxt -> False DerivClauseCtxt -> False + SigmaCtxt -> False _ -> True check_h98_arg_shape = case ctxt of diff --git a/testsuite/tests/typecheck/should_compile/T20033.hs b/testsuite/tests/typecheck/should_compile/T20033.hs new file mode 100644 index 0000000000..24323a238b --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T20033.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE QuantifiedConstraints #-} +{-# LANGUAGE ConstraintKinds #-} + +module T20033 where + +import Data.Typeable + +data Some c where + Some :: c a => a -> Some c + +extractSome :: (Typeable a, forall x. c x => Typeable x) => Some c -> Maybe a +extractSome (Some a) = cast a diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T index 429ac69ce0..a275d5196a 100644 --- a/testsuite/tests/typecheck/should_compile/all.T +++ b/testsuite/tests/typecheck/should_compile/all.T @@ -792,3 +792,4 @@ test('T18481', normal, compile, ['']) test('T18481a', normal, compile, ['']) test('T19775', normal, compile, ['']) test('T17817b', normal, compile, ['']) +test('T20033', normal, compile, ['']) |