Summary:
This patch fixes #15806, where we found that the `:k` command in GHCi
misses a validity checking for the type.
Missing validity checking causes `:k` to accept types that are not validated.
For example, `:k (Maybe (forall a. a -> a))` (incorrectly) returns `*`, while
impredictivity of type instantiation shouldn't be allowed.
Test Plan: ./validate
Reviewers: simonpj, goldfire, bgamari
Reviewed By: bgamari
Subscribers: rwbarton, carter
GHC Trac Issues: #15806
Differential Revision: https://phabricator.haskell.org/D5265
tcHsSigWcType :: UserTypeCtxt -> LHsSigWcType GhcRn -> TcM Type
-- This one is used when we have a LHsSigWcType, but in
tcHsSigWcType :: UserTypeCtxt -> LHsSigWcType GhcRn -> TcM Type
-- This one is used when we have a LHsSigWcType, but in
--- a place where wildards aren't allowed. The renamer has
+-- a place where wildcards aren't allowed. The renamer has
-- already checked this, so we can simply ignore it.
tcHsSigWcType ctxt sig_ty = tcHsSigType ctxt (dropWildCards sig_ty)
-- already checked this, so we can simply ignore it.
tcHsSigWcType ctxt sig_ty = tcHsSigType ctxt (dropWildCards sig_ty)
import RnSplice ( rnTopSpliceDecls, traceSplice, SpliceInfo(..) )
import IfaceEnv( externaliseName )
import TcHsType
import RnSplice ( rnTopSpliceDecls, traceSplice, SpliceInfo(..) )
import IfaceEnv( externaliseName )
import TcHsType
+import TcValidity( checkValidType )
import TcMatches
import Inst( deeplyInstantiate )
import TcUnify( checkConstraints )
import TcMatches
import Inst( deeplyInstantiate )
import TcUnify( checkConstraints )
; kvs <- kindGeneralize kind
; ty <- zonkTcTypeToType ty
; kvs <- kindGeneralize kind
; ty <- zonkTcTypeToType ty
+ -- Do validity checking on type
+ ; checkValidType GhciCtxt ty
+
; ty' <- if normalise
then do { fam_envs <- tcGetFamInstEnvs
; let (_, ty')
; ty' <- if normalise
then do { fam_envs <- tcGetFamInstEnvs
; let (_, ty')
--- /dev/null
+:set -XRankNTypes
+:k (Maybe Int)
+:k (Maybe (forall a. a -> a))
\ No newline at end of file
--- /dev/null
+<interactive>:1:1: error:
+ Illegal polymorphic type: forall a. a -> a
+ GHC doesn't yet support impredicative polymorphism
\ No newline at end of file
--- /dev/null
+(Maybe Int) :: *
\ No newline at end of file
test('T14963b', just_ghci, ghci_script, ['T14963b.script'])
test('T14963c', [extra_hc_opts("-fdefer-type-errors")], ghci_script, ['T14963c.script'])
test('T15007', just_ghci, ghci_script, ['T15007.script'])
test('T14963b', just_ghci, ghci_script, ['T14963b.script'])
test('T14963c', [extra_hc_opts("-fdefer-type-errors")], ghci_script, ['T14963c.script'])
test('T15007', just_ghci, ghci_script, ['T15007.script'])
+test('T15806', just_ghci, ghci_script, ['T15806.script'])