Commit c4a876d5 authored by Ningning Xie's avatar Ningning Xie Committed by Ben Gamari

Fix `:k` command: add validity checking

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:
parent 134de451
......@@ -174,7 +174,7 @@ pprSigCtxt ctxt hs_ty
tcHsSigWcType :: UserTypeCtxt -> LHsSigWcType GhcRn -> TcM Type
-- This one is used when we have a LHsSigWcType, but in
-- 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)
......@@ -51,6 +51,7 @@ import {-# SOURCE #-} TcSplice ( finishTH, runRemoteModFinalizers )
import RnSplice ( rnTopSpliceDecls, traceSplice, SpliceInfo(..) )
import IfaceEnv( externaliseName )
import TcHsType
import TcValidity( checkValidType )
import TcMatches
import Inst( deeplyInstantiate )
import TcUnify( checkConstraints )
......@@ -2397,6 +2398,9 @@ tcRnType hsc_env normalise rdr_type
; kvs <- kindGeneralize kind
; ty <- zonkTcTypeToType ty
-- Do validity checking on type
; checkValidType GhciCtxt ty
; ty' <- if normalise
then do { fam_envs <- tcGetFamInstEnvs
; let (_, ty')
:set -XRankNTypes
:k (Maybe Int)
:k (Maybe (forall a. a -> a))
\ No newline at end of file
<interactive>:1:1: error:
Illegal polymorphic type: forall a. a -> a
GHC doesn't yet support impredicative polymorphism
\ No newline at end of file
(Maybe Int) :: *
\ No newline at end of file
......@@ -35,3 +35,4 @@ test('T14963a', just_ghci, ghci_script, ['T14963a.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'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment